Module: ExtendHash
- Included in:
- Hash
- Defined in:
- lib/net/dns/rr.rb,
lib/net/dns/resolver.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#-(oth) ⇒ Object
Performs a sort of group difference operation on hashes or arrays.
-
#key_downcase! ⇒ Object
Returns an hash with all the keys turned into downcase.
Instance Method Details
#-(oth) ⇒ 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}
393 394 395 396 397 398 399 400 |
# File 'lib/net/dns/rr.rb', line 393 def -(oth) case oth when Hash delete_if {|k,v| oth.has_key? k} when Array delete_if {|k,v| oth.include? k} end end |
#key_downcase! ⇒ Object
Returns an hash with all the keys turned into downcase
hsh = {"Test" => 1, "FooBar" => 2}
hsh.key_downcase!
#=> {"test"=>1,"foobar"=>2}
1259 1260 1261 1262 1263 1264 1265 |
# File 'lib/net/dns/resolver.rb', line 1259 def key_downcase! hsh = Hash.new self.each do |key,val| hsh[key.downcase] = val end self.replace(hsh) end |