Sha256: f94b86db1b0b4f402f59859810feadde1f8522ad6f0ceffbf91afdd3b48e127b

Contents?: true

Size: 517 Bytes

Versions: 1

Compression:

Stored size: 517 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
  # CREDIT: Xavier Shay (bug fix)

  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

1 entries across 1 versions & 1 rubygems

Version Path
facets-2.9.3 lib/core/facets/hash/op_sub.rb