rails/rails — pull request #17485 by kevinmarx (2014-11-02 18:08:34+00:00)
Title: Hash#coalesce

Method for merging multiple hashes onto a single hash where arguments override the previous argument in-order. This functionality is based off of `_.extend` from the Underscore.js library. I considered overriding default `#merge`, but I think that a new method is more explicit to what is happening.

Before:
```ruby
h1 = { a: true, b: "foo" }
h2 = { c: "bar" }
h3 = { b: "baz" }

[h2, h3].each { |hsh| h1.merge!(hsh) }
h1 #=> { a: true, b: "baz", c: "bar" }
# you would need to dup the target hash first if you didn't want to modify the original
```

After:
```ruby
h1 = { a: true, b: "foo" }
h2 = { c: "bar" }
h3 = { b: "baz" }

h1.coalesce(h2, h3)
#=> { a: true, b: "baz", c: "bar" }
# `coalesce` returns a new hash, `coalesce!` will modify the original.
```