Is there any difference between:
@attr[:field] = new_value
and
@attr.merge(:field => new_value)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re using
merge!instead ofmerge, there is no difference.The only difference is that you can use multiple fields (meaning: another hash) in the merge parameters.
Example:
When assigning single values, I would prefer
h[:field] = new_valovermergefor readability reasons and I guess it is faster than merging.You can also take a look at the Hash-rdoc: http://ruby-doc.org/core/classes/Hash.html#M000759