-1

I got this:

first = [['lorem1','lorem1','lorem1',...],['lorem2','lorem2','lorem2',...],...]
second = [value1,value2,value3, ...]

I want to do something like that:

my_array_of_hash = [{value 1 =>lorem1, value2 => lorem1}, {value1 =>lorem2, value2 => lorem2}, .... ]

Can you help me with that please?

1 Answer 1

3
hashes_array = []
first.each do |array|
  hashes_array << Hash[second.zip array]
end

or:

hashes_array = first.map do |array|
  Hash[second.zip array]
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.