Module: Sapphire::Configuration::AttrMethods
- Included in:
- Sapphire
- Defined in:
- lib/sapphire/Configuration/AttrMethods.rb
Instance Method Summary collapse
Instance Method Details
#attr_array(*names) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sapphire/Configuration/AttrMethods.rb', line 6 def attr_array(*names) names.each do |n| self.send :define_method, n do |*value| if value.nil? || value.empty? return instance_variable_get("@#{n}") else self.send "#{n}=".to_sym, value.to_ary.flatten end end self.send :define_method, "#{n}=" do |value| instance_variable_set("@#{n}", value) end end end |
#attr_hash(*names) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sapphire/Configuration/AttrMethods.rb', line 21 def attr_hash(*names) names.each do |n| self.class_eval(<<-EOF, __FILE__, __LINE__) def #{n}(*value) if value.nil? || value.empty? instance_variable_get("@#{n}") else instance_variable_set("@#{n}", value[0]) end end EOF self.send :define_method, "#{n}=" do |value| instance_variable_set("@#{n}", value) end end end |