Ruby – How to add new item to hash


I'm new to Ruby and don't know how to add new item to already existing hash. For example, first I construct hash:

hash = {item1: 1}

after that a want to add item2 so after this I have hash like this:

{item1: 1, item2: 2}

I don't know what method to do on hash, could someone help me?

Best Solution

Create the hash:

hash = {:item1 => 1}

Add a new item to it:

hash[:item2] = 2