hash-deep-merge

TIL that Hash#deep_merge accepts a block in which you can specify how values from the same key should be merged:

h1 = { a: { b: 1 }, c: 2}
h2 = { a: { d: 3 }, c: 4}

h1.deep_merge(h2)
# => { a: { b: 1, d: 3 }, c: 4 }

h1.deep_merge(h2) { |k, v1, v2| v1 + v2 }
# => { a: { b: 1, d: 3 }, c: 6 }