I have:
a = [{:a=1,"b=2,:c=3},{:a=4,:b=5,:c=6},..] (including 2 items with 3 keys)
b = [{:d=7},{:d=8},...] (including 2 items with 1 key)
At final I need to have 2 items with 4 keys:
a = [{:a=1,:b=2,:c=3,:d=7},{:a=4,:b=5,:c=6,:d=8},..]
Please help, tried to do the following:
a.each do |item|
b.each do |view|
item.merge!(view)
end
end
But at final I have in two items the same dates as for item one in array b (d=7).
First of all your definitions of a and b are not very valid. You need to use either symbols or strings a is not a valid key for a hash. Also you should use => to point a key to value.
Here is how you can achieve what you want to do:
Zip performs the operation on each matching pair of elements in a and b – precisely what you want.