Reputation: 19526
h = {1=>[1,2,3], 2=>[4,5,6]} new_arr = [] h.each_value {|arr| new_arr.concat(arr) }
This works, but what's a more ruby-like way to do it?
All values are arrays but the elements of each array should not be modified.
Upvotes: 1
Views: 779
Reputation: 81530
Slightly cryptic
h.flat_map(&:last)
Slightly verbose
h.flat_map{|_, value| value}
Upvotes: 1
Reputation: 1484
If you want to get the array of hash value, use Hash#values.
new_arr = h.values
Upvotes: 0