Reputation: 16685
Say I have the following hash.
my_hash = {
'array1' => %w[
value1
value2
],
'array2' => %w[
value3
value4
]
}
How do I make an array that looks like
my_array = %w[value1 value2 value3 valuu4]
Upvotes: 1
Views: 522
Reputation: 2335
my_array = my_hash.values.flatten
=> ["value1", "value2", "value3", "value4"]
Upvotes: 3
Reputation: 84343
Use Hash#values to collect the values from your Hash, and then use Array#flatten to turn the result into a single Array rather than one containing nested arrays. For example:
my_hash.values.flatten
#=> ["value1", "value2", "value3", "value4"]
Upvotes: 1