Given two hashes whose values are arrays, what is the best way to merge them so that when the two shares some key, the resulting value will be the concatenation of the values of the original two hashes? For example, given two hashes h1 and h2:
h1 = Hash.new{[]}.merge(a: [1], b: [2, 3])
h2 = Hash.new{[]}.merge(b: [4], c: [5])
I expect that the method convolute will give:
h1.convolute(h2) #=> {:a => [1], b: [2, 3, 4], c: [5]}
This is exactly what
Hash#mergedoes if you give it a block:http://rubydoc.info/stdlib/core/1.9.2/Hash:merge