O
O
Ord EO2021-05-04 10:48:24
ruby
Ord EO, 2021-05-04 10:48:24

How to build an array of hashes from an array of keys and an array of arrays of values?

There are values: . There are keys: . Get an array of hashes:
['el1', 'el2', 'el3']

[ {:el1 => 1, :el2=>2, :el3 =>3}, {:el1 => 32, :el2=>33, :el3 =>2}, {:el1 => 23, :el2=>12, :el3 =>0}} ]

How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-05-04
@OrdeO

values.map{|n| Hash[keys.map(&:to_sym).zip(n)]}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question