groceries=[{"bread"=>"2", "eggs"=>"3", "cheese"=>"1", "butter"=>"4"},
{"juice"=>"3", "milk"=>"1", "tea"=>"1", "sugar"=>"1"}]
如何迭代每个散列并将其插入单独的数组? 我想要看起来像这样的东西:
items = [["bread","eggs","cheese","butter"],["juice","milk","tea","sugar"]]
最佳答案
试试这个
groceries.map(&:keys)
=> [["bread", "eggs", "cheese", "butter"], ["juice", "milk", "tea", "sugar"]]
关于ruby - 遍历ruby中的多维哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41795890/