Module: SimplyUseful::HasAttributes
- Defined in:
- lib/simply_useful/has_attributes.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #initialize(attributes = nil) {|_self| ... } ⇒ Object
Instance Method Details
#attributes ⇒ Object
15 16 17 18 19 |
# File 'lib/simply_useful/has_attributes.rb', line 15 def attributes attributes = instance_variables attributes.delete("@errors") Hash[*attributes.collect { |attribute| [attribute[1..-1].to_sym, instance_variable_get(attribute)] }.flatten] end |
#attributes=(attributes) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/simply_useful/has_attributes.rb', line 8 def attributes=(attributes) # , guard_protected_attributes = true #attributes = filter_attributes(attributes) if !attributes.blank? && guard_protected_attributes attributes.each do |key, value| send(key.to_s + '=', value) end if attributes end |
#initialize(attributes = nil) {|_self| ... } ⇒ Object
3 4 5 6 |
# File 'lib/simply_useful/has_attributes.rb', line 3 def initialize(attributes = nil) self.attributes = attributes yield self if block_given? end |