How can I assign multiple values to a hash key?

后端 未结 4 626
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 13:55

For the sake of convenience I am trying to assign multiple values to a hash key in Ruby. Here\'s the code so far

myhash = { :name => [\"Tom\" , \"Dick\" ,         


        
4条回答
  •  没有蜡笔的小新
    2020-12-30 14:37

    myhash.each_pair {|k,v| v.each {|n| puts "#{k} => #{n}"}}
    #name => Tom
    #name => Dick
    #name => Harry
    

    The output format is not exactly what you need, but I think you get the idea.

提交回复
热议问题