Method: Hash#diff

Defined in:
lib/core/facets/hash/diff.rb

#diff(hash) ⇒ Object

Difference comparison of two hashes.

h1 = {:a=>1,:b=>2}
h2 = {:a=>1,:b=>3}

h1.diff(h2)  #=> {:b=>2}
h2.diff(h1)  #=> {:b=>3}


11
12
13
14
15
# File 'lib/core/facets/hash/diff.rb', line 11

def diff(hash)
  h1 = self.dup.delete_if{ |k,v| hash[k] == v }
  h2 = hash.dup.delete_if{ |k,v| has_key?(k) }
  h1.merge(h2)
end