How to add new item to hash

前端 未结 7 1238
余生分开走
余生分开走 2020-12-22 18:44

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

7条回答
  •  误落风尘
    2020-12-22 19:15

    hash[key]=value Associates the value given by value with the key given by key.

    hash[:newKey] = "newValue"
    

    From Ruby documentation: http://www.tutorialspoint.com/ruby/ruby_hashes.htm

提交回复
热议问题