Module: BootstrapHamlHelpers::Component::InheritableTraits::ClassMethods
- Defined in:
- app/models/bootstrap_haml_helpers/component/inheritable_traits.rb
Instance Method Summary collapse
Instance Method Details
#inherited(subclass) ⇒ Object
27 28 29 30 31 32 |
# File 'app/models/bootstrap_haml_helpers/component/inheritable_traits.rb', line 27 def inherited(subclass) (["traits"] + traits).each do |t| ivar = "@#{t}" subclass.instance_variable_set(ivar, instance_variable_get(ivar)) end end |
#traits(*attrs) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/bootstrap_haml_helpers/component/inheritable_traits.rb', line 8 def traits(*attrs) @traits ||= [] @traits += attrs attrs.each do |attr| class_eval %{ def self.#{attr}(string = nil) @#{attr} = string || @#{attr} end def self.#{attr}=(string = nil) #{attr}(string) end def #{attr} self.class.instance_variable_get('@#{attr}') end } end @traits end |