I’m looking for a elegant way to assign the value stored inside an Hash into a pre-existed object.
Just to be clear, if I have an object, say obj with two attributes, say name and age, I want to assign this values coming from an hash without do something like:
obj.name = hash[:name]
obj.age = hash[:age]
Thanks for your attention.
Simone
Best bet is probably to simply define a method like
update_attributeswhich takes a hash and does it inside an instance method of the class.Expanding on what others have written and what you seem to need I think your best bet would be:
This will account for: