Hard case with array which using hases inside (ruby) -


i have:
a = [{:a=1,"b=2,:c=3},{:a=4,:b=5,:c=6},..] (including 2 items 3 keys)
b = [{:d=7},{:d=8},...] (including 2 items 1 key)

at final need have 2 items 4 keys:
a = [{:a=1,:b=2,:c=3,:d=7},{:a=4,:b=5,:c=6,:d=8},..]

please help, tried following:

a.each |item|    b.each |view|      item.merge!(view)          end end 

but @ final have in 2 items same dates item 1 in array b (d=7).

first of definitions of , b not valid. need use either symbols or strings not valid key hash. should use => point key value. here how can achieve want do:

a = [{:a=>1,:b=>2,:c=>3},{:a=>4,:b=>5,:c=>6}] b =[{:d=>7}, {:d=>8}] a.zip(b) |x,y|   x.merge!(y) end 

zip performs operation on each matching pair of elements in , b - precisely want.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -