Ruby converting array of hashes to array of arrays
2014-09-26 09:00
375 查看
I have a ruby array of hashes
What is the best way to convert this to
in ruby.
Use map.
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]}
相关文章推荐
- Converting a array to an array of ranges in ruby
- Whats the best way to split an array in ruby into multiple smaller arrays of random size
- How to limit an array of similar hashes to those that have more than one of the same key:value pair
- Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings
- ruby merge array of hashes based on the key and order it by number of key/value pair
- How to combine the value of multiple hashes within an array by the same key
- Ruby: how to sort array of string parsing the content
- How to find number of a specific integer in an array of Fixnums ruby
- How to sort an array of hashes into hashes with multiple values for a key?
- Condensing an array of hashes within that same array in Ruby
- Ruby remove substring matching to any element of array
- how to merge array of hash based same keys in ruby?
- Array to hash of arrays
- Extracting Data from array of hashes Ruby
- Ruby array of two dimensional arrays, search/lookup?
- Matching Portions of A String to Elements of an Array in Ruby
- array summation and merging based on uniqueness of element at certain position + ruby arrays
- Convert array of key value object to object of the key values (ruby)
- how to set interface arrays : Illegal index into array of interfaces
- [轉]Array of pointer VS. Pointer to Array