Module: Cura::Attributes::HasAttributes::ClassMethods
- Defined in:
- lib/cura/attributes/has_attributes.rb
Overview
The class methods to be mixed in when included.
Instance Method Summary collapse
Instance Method Details
#attribute(name, options = {}, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cura/attributes/has_attributes.rb', line 7 def attribute(name, ={}, &block) = .to_h if [:query] define_method("#{name}?") { instance_variable_get("@#{name}") } else attr_reader(name) end if [:query] define_method("#{name}=") do |value| value = instance_exec(value, , &block) unless block.nil? instance_variable_set("@#{name}", !!value) end else define_method("#{name}=") do |value| value = instance_exec(value, , &block) unless block.nil? instance_variable_set("@#{name}", value) end end end |