tbrent tbrent - 1 year ago 136
Ruby Question

Convert array of hashes to array

I have a array of hashes that i need the value side of the hashes in an array.
The array of hashes look like this with a couple thousand of them.

{:code=>"404"}, {:code=>"302"}, {:code=>"200"}

I have looked but can only find where it converts from a hash.
How would I go about doing this?

Answer Source
a=[{:code=>"404"}, {:code=>"302"}, {:code=>"200"}] 
puts a.map{|x|x.values}.flatten.inspect


["404", "302", "200"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download