Sha256: 6601781ea6c74cec04978c39e46a32f2c7aabedaf4de66af200c537bb76a40aa

Contents?: true

Size: 519 Bytes

Versions: 3

Compression:

Stored size: 519 Bytes

Contents

class Hash

  # Operator for removing hash pairs. 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

3 entries across 3 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/hash/op_sub.rb
facets-3.1.0 lib/core/facets/hash/op_sub.rb
facets-3.0.0 lib/core/facets/hash/op_sub.rb