Ruby converting array of hashes to array of arrays

I have a ruby array of hashes

arr1 = [:a => {:name=>"Bob",:age=>"10",:city=>"NY"},
        :b => {:name=>"Mike",:age=>"20",:city=>"FL"}]

What is the best way to convert this to

arr2 = [["Bob",10],["Mike",20]]

in ruby.

Use map.

arr1.first.values.map{|h| [h[:name], h[:age].to_i]}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章