Class: Class
- Inherits:
-
Object
- Object
- Class
- 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 <<-RUBY, __FILE__, __LINE__ + 1 def self.#{name}() nil end def self.#{name}?() !!#{name} end def self.#{name}=(val) singleton_class.class_eval do remove_possible_method(:#{name}) define_method(:#{name}) { val } end val end RUBY end end |