Ruby Hash to array of values

tbrooke picture tbrooke · Mar 5, 2012 · Viewed 174.2k times · Source

I have this:

hash  = { "a"=>["a", "b", "c"], "b"=>["b", "c"] } 

and I want to get to this: [["a","b","c"],["b","c"]]

This seems like it should work but it doesn't:

hash.each{|key,value| value}
=> {"a"=>["a", "b", "c"], "b"=>["b", "c"]} 

Any suggestions?

Answer

Ray Toal picture Ray Toal · Mar 5, 2012

Also, a bit simpler....

>> hash = { "a"=>["a", "b", "c"], "b"=>["b", "c"] }
=> {"a"=>["a", "b", "c"], "b"=>["b", "c"]}
>> hash.values
=> [["a", "b", "c"], ["b", "c"]]

Ruby doc here