Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/rainman/support.rb

Overview

From lib/active_support/core_ext/hash/reverse_merge.rb

Instance Method Summary collapse

Instance Method Details

#reverse_merge(other_hash) ⇒ Object

Public: Reverse merge a hash.

Example

a = { :one => :A }
b = a.reverse_merge(:one => :B, :two => :two)
a #=> { :one => :A }
b #=> { :one => :A, :two => :two }

Returns a new Hash.



73
74
75
# File 'lib/rainman/support.rb', line 73

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

#reverse_merge!(other_hash) ⇒ Object Also known as: reverse_update

Public: Reverse merge a hash in-place.

Example

a = { :one => :A }
a.reverse_merge!(:one => :B, :two => :two)
a #=> { :one => :A, :two => :two }

Returns a Hash.



86
87
88
89
# File 'lib/rainman/support.rb', line 86

def reverse_merge!(other_hash)
  # right wins if there is no left
  merge!( other_hash ){|key,left,right| left }
end