Rails - add multiple new elements to Hash

There are many way to add some new elements to Hash using Ruby On Rails. However, I reccomend to use merge! Why ?

By using merge! , you can combine it in a looping block to add as much as new elements to your Hash, event it's inititated by empty Hash. Here is the example :

arr_of_hash = [{},{},{}]
0.upto(2) {
arr_of_hash[0].merge! i.to_s=>i #output : {"0"=>0,"1"=>1,"2"=>2}
}
puts arr_of_hash # [{"0"=>0,"1"=>1,"2"=>2},{},{}]

You can try the codes above in your Rails console. Starting from there, you can vary and modify it to create more complicated Hash.