Learn Ruby
Hash
15.9
Lesson

merge to add more data to hash

We have seen that we can use merge! to add new key and values to hash. merge! changes the original hash.

If we do not want to change the original hash then we can use merge. merge returns the new hash without altering the original hash.

As we can see here the original hash remains unchanged and the new hash2 has new the new key and the new value.