Ruby Inserting Key, Value elements in Hash

后端 未结 2 1771
别那么骄傲
别那么骄傲 2021-02-08 01:15

I want to add elements to my Hash lists, which can have more than one value. Here is my code. I don\'t know how I can solve it!

class dictionary

  def initializ         


        
2条回答
  •  佛祖请我去吃肉
    2021-02-08 01:55

    Probably, you want to merge two Hashes?

    my_hash = { "key1"=> value1 }
    another_hash = { "key2"=> value2 }
    my_hash.merge(another_hash) # => { "key1"=> value1, "key2"=> value2 }
    

提交回复
热议问题