Module: Hashtostruct::HashToStruct
- Defined in:
- lib/hashtostruct.rb
Instance Method Summary collapse
- #to_obj ⇒ Object
-
#to_struct ⇒ Object
Takes a Hash and converts it into a Struct with each key as a property each value converted into a native object if possible.
Instance Method Details
#to_obj ⇒ Object
82 83 84 |
# File 'lib/hashtostruct.rb', line 82 def to_obj to_struct end |
#to_struct ⇒ Object
Takes a Hash and converts it into a Struct with each key as a property each value converted into a native object if possible.
75 76 77 78 79 80 |
# File 'lib/hashtostruct.rb', line 75 def to_struct hash = self Struct.new(*(hash.inject([]) { |res,val| res << val[0].to_sym })).new(*( hash.inject([]) { |res,val| res << val[1].to_obj} )) end |