Вы можете сделать это:
array = [[1, [-1, 1]], [1, [20, 8]], [1, [30, 4]],
[1, [40, 2]], [1, [41, 6]], [1, [70, 243]]]
# map into hashes that can be merged together
hashes = array.map do |key,value|
{ key => [value] }
end
# fold all hashes into one hash by merging the values by key
merged_hash = hashes.inject({}) do |accu,value|
accu.merge!(value) {|_,o,n| o|n }
end
Это можно записать не так просто: 1 1004 *
array.map{|k,v|{k=>[v]}}.inject({}){|a,v|a.merge!(v){|_,o,n|o|n}}
#==> {1=>[[-1, 1], [20, 8], [30, 4], [40, 2], [41, 6], [70, 243]]}