Module: Lean::Utils::InheritableClassAttributes::ClassMethods
- Defined in:
- lib/lean-utils/inheritable_class_attributes/class_methods.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #inheritable_class_attr(attr_name) ⇒ Object
- #inherited(subclass) ⇒ Object
- #inherited_class_attribute_method(attribute) ⇒ Object
Instance Attribute Details
#_inheritable_class_attrs ⇒ Object
7 8 9 |
# File 'lib/lean-utils/inheritable_class_attributes/class_methods.rb', line 7 def _inheritable_class_attrs @_inheritable_class_attrs ||= [] end |
Instance Method Details
#inheritable_class_attr(attr_name) ⇒ Object
11 12 13 |
# File 'lib/lean-utils/inheritable_class_attributes/class_methods.rb', line 11 def inheritable_class_attr(attr_name) self._inheritable_class_attrs += Array(attr_name) end |
#inherited(subclass) ⇒ Object
15 16 17 18 19 |
# File 'lib/lean-utils/inheritable_class_attributes/class_methods.rb', line 15 def inherited(subclass) _inheritable_class_attrs.each do |attribute| subclass.instance_eval(inherited_class_attribute_method(attribute)) end end |
#inherited_class_attribute_method(attribute) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lean-utils/inheritable_class_attributes/class_methods.rb', line 21 def inherited_class_attribute_method(attribute) " def \#{attribute}(*args)\n if @\#{attribute}.nil?\n @\#{attribute} = begin\n superclass.\#{attribute}.clone\n rescue TypeError\n superclass.\#{attribute}\n end\n end\n\n super\n end\n EOS\nend\n" |