Module: Arli::Helpers::Inherited::ClassMethods
- Defined in:
- lib/arli/helpers/inherited.rb
Instance Method Summary collapse
- #attr_assignable(*attrs) ⇒ Object
- #set_or_get(var_name, val = nil, set_nil = false) ⇒ Object
- #short_name ⇒ Object
Instance Method Details
#attr_assignable(*attrs) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/arli/helpers/inherited.rb', line 17 def attr_assignable(*attrs) self.class.instance_eval do attrs.each do |attribute| send(:define_method, attribute) do |val = nil, **opts| set_or_get(attribute, val, opts && opts[:nil]) end end end end |
#set_or_get(var_name, val = nil, set_nil = false) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/arli/helpers/inherited.rb', line 6 def set_or_get(var_name, val = nil, set_nil = false) var = "@#{var_name}".to_sym self.instance_variable_set(var, val) if val self.instance_variable_set(var, nil) if set_nil self.instance_variable_get(var) end |
#short_name ⇒ Object
13 14 15 |
# File 'lib/arli/helpers/inherited.rb', line 13 def short_name name.gsub(/.*::/, '').underscore.to_sym end |