Sha256: e9e17931b2640b8806a8eda38a523790b0d791260cf05aa0799c743c7b213549

Contents?: true

Size: 483 Bytes

Versions: 16

Compression:

Stored size: 483 Bytes

Contents

class Hash

  # Operator for remove hash paris. If another hash is given
  # the pairs are only removed if both key and value are equal.
  # If an array is given then matching keys are removed.
  #
  # CREDIT: Trans

  def -(other)
    h = self.dup
    if other.respond_to?(:to_ary)
      other.to_ary.each do |k|
        h.delete(k)
      end
    else
      other.each do |k,v|
        if h.key?(k)
          h.delete(k) if v == h[k]
        end
      end
    end
    h
  end

end

Version data entries

16 entries across 15 versions & 1 rubygems

Version Path
facets-2.9.2 src/core/facets/hash/op_sub.rb
facets-2.9.2 lib/core/facets/hash/op_sub.rb
facets-2.9.1 lib/core/facets/hash/op_sub.rb
facets-2.9.0 lib/core/facets/hash/op_sub.rb
facets-2.9.0.pre.2 lib/core/facets/hash/op_sub.rb
facets-2.9.0.pre.1 lib/core/facets/hash/op_sub.rb
facets-2.8.4 lib/core/facets/hash/op_sub.rb
facets-2.8.3 lib/core/facets/hash/op_sub.rb
facets-2.8.2 lib/core/facets/hash/op_sub.rb
facets-2.8.1 lib/core/facets/hash/op_sub.rb
facets-2.8.0 lib/core/facets/hash/op_sub.rb
facets-2.7.0 lib/core/facets/hash/op_sub.rb
facets-2.6.0 lib/core/facets/hash/op_sub.rb
facets-2.5.1 lib/core/facets/hash/op_sub.rb
facets-2.5.0 lib/core/facets/hash/op_sub.rb
facets-2.5.2 lib/core/facets/hash/op_sub.rb