Module: HashConstructed
- Included in:
- Logan::Comment, Logan::Event, Logan::Message, Logan::Person, Logan::Project, Logan::ProjectTemplate, Logan::Todo, Logan::TodoList
- Defined in:
- lib/logan/HashConstructed.rb
Overview
this module is taken from the accepted answer here stackoverflow.com/questions/1572660/is-there-a-way-to-initialize-an-object-through-a-hash
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#json_raw ⇒ Object
Returns the value of attribute json_raw.
Instance Method Summary collapse
-
#initialize(h) ⇒ Object
initalizes the object by pulling key-value pairs from the hash and mapping them to the object’s instance variables.
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/logan/HashConstructed.rb', line 6 def attributes @attributes end |
#json_raw ⇒ Object
Returns the value of attribute json_raw.
6 7 8 |
# File 'lib/logan/HashConstructed.rb', line 6 def json_raw @json_raw end |
Instance Method Details
#initialize(h) ⇒ Object
initalizes the object by pulling key-value pairs from the hash and mapping them to the object’s instance variables
12 13 14 15 16 17 18 |
# File 'lib/logan/HashConstructed.rb', line 12 def initialize(h) @attributes = h h.each do |k,v| next unless respond_to?("#{k}=") send("#{k}=",v) end end |