Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#diff(other) ⇒ Object

Stolen from Rails 4.0.5 since this has been removed!

Returns a hash that represents the difference between two hashes.

{1 => 2}.diff(1 => 2)         # => {}
{1 => 2}.diff(1 => 3)         # => {1 => 2}
{}.diff(1 => 2)               # => {1 => 2}
{1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}

15
16
17
# File 'lib/validation_matcher.rb', line 15

def diff other
  dup.delete_if { |k, v| other[k] == v }.merge!(other.dup.delete_if { |k, v| has_key?(k) })
end