Module: Net::DNS::HashOperators

Included in:
Hash
Defined in:
lib/net/dns/core_ext.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#-(other) ⇒ Object

Performs a sort of group difference operation on hashes or arrays

a = {:a=>1,:b=>2,:c=>3}
b = {:a=>1,:b=>2}
c = [:a,:c]
a-b #=> {:c=>3}
a-c #=> {:b=>2}


34
35
36
37
38
39
40
41
# File 'lib/net/dns/core_ext.rb', line 34

def -(other)
  case other
    when Hash
      delete_if { |k,v| other.has_key?(k) }
    when Array
      delete_if { |k,v| other.include?(k) }
  end
end