Module: Perry::Support::ClassAttributes::ClassMethods
- Defined in:
- lib/perry/support/class_attributes.rb
Instance Method Summary collapse
- #class_attribute(*attrs) ⇒ Object (also: #class_attributes)
- #inherited(subclass) ⇒ Object
Instance Method Details
#class_attribute(*attrs) ⇒ Object Also known as: class_attributes
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/perry/support/class_attributes.rb', line 11 def class_attribute(*attrs) @class_attributes ||= [] @class_attributes += attrs attrs.each do |attr| class_eval %{ def self.#{attr} @#{attr} end def self.#{attr}=(value = nil) @#{attr} = value end def #{attr} self.class.#{attr} end def #{attr}=(value = nil) self.class.#{attr} = value end } end @class_attributes end |
#inherited(subclass) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/perry/support/class_attributes.rb', line 34 def inherited(subclass) (["class_attributes"] + class_attributes).each do |t| ivar = "@#{t}" value = instance_variable_get(ivar) subclass.instance_variable_set( ivar, value.duplicable? ? value.dup : value ) end end |