Sha256: d2a2a4796f3f4e68f12d4e8304a1a91a06b535455bdd592d839196bbb50775b0

Contents?: true

Size: 321 Bytes

Versions: 10

Compression:

Stored size: 321 Bytes

Contents

class Hash

  # 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}
  #
  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

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/hash/diff.rb
facets-3.1.0 lib/core/facets/hash/diff.rb
facets-3.0.0 lib/core/facets/hash/diff.rb
facets-2.9.3 lib/core/facets/hash/diff.rb
facets-2.9.2 src/core/facets/hash/diff.rb
facets-2.9.2 lib/core/facets/hash/diff.rb
facets-2.9.1 lib/core/facets/hash/diff.rb
facets-2.9.0 lib/core/facets/hash/diff.rb
facets-2.9.0.pre.2 lib/core/facets/hash/diff.rb
facets-2.9.0.pre.1 lib/core/facets/hash/diff.rb