[Solved] Why are there three variables with `merge` method?


If you read the documentation, you will learn it’s: key, old value, and new value.

h1.merge(h2) { |key, old, new| new - old } 

means the final result will have value h2[key] - h1[key]. Since you are merging h2 over h1, values from h2 will be new values and those from h1 will be old values.

solved Why are there three variables with `merge` method?