Method: Hash#reverse_merge

Defined in:
activesupport/lib/active_support/core_ext/hash/reverse_merge.rb

#reverse_merge(other_hash) ⇒ Object Also known as: with_defaults

Merges the caller into other_hash. For example,

options = options.reverse_merge(size: 25, velocity: 10)

is equivalent to

options = { size: 25, velocity: 10 }.merge(options)

This is particularly useful for initializing an options hash with default values.



14
15
16
# File 'activesupport/lib/active_support/core_ext/hash/reverse_merge.rb', line 14

def reverse_merge(other_hash)
  other_hash.merge(self)
end