Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/exceptioner/core_ext/class/attribute.rb

Overview

This code is stolen from ActiveSupport gem. We don't need to instance accessors so they're removed for cattr_ methods so responsible part of code was removed.

Note we don't overwrite class_attribute method if it exists already.

Instance Method Summary collapse

Instance Method Details

#class_attribute(*attrs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/exceptioner/core_ext/class/attribute.rb', line 11

def class_attribute(*attrs)
  attrs.each do |name|
    class_eval "      def self.\#{name}() nil end\n      def self.\#{name}?() !!\#{name} end\n\n      def self.\#{name}=(val)\n        singleton_class.class_eval do\n          remove_possible_method(:\#{name})\n          define_method(:\#{name}) { val }\n        end\n        val\n      end\n    RUBY\n\n  end\nend\n", __FILE__, __LINE__ + 1