How to add new item to hash

前端 未结 7 1216
余生分开走
余生分开走 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:01

    Create hash as:

    h = Hash.new
    => {}
    

    Now insert into hash as:

    h = Hash["one" => 1]
    

提交回复
热议问题