Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code cleanup. Moved core extensions into a separate file.
- Loading branch information
Showing
7 changed files
with
233 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Net # :nodoc: | ||
module DNS | ||
|
||
module HashKeys # :nodoc: | ||
|
||
# Returns an hash with all the | ||
# keys turned into downcase | ||
# | ||
# hsh = {"Test" => 1, "FooBar" => 2} | ||
# hsh.downcase_keys! | ||
# #=> {"test"=>1,"foobar"=>2} | ||
# | ||
def downcase_keys! | ||
hsh = Hash.new | ||
self.each do |key,val| | ||
hsh[key.downcase] = val | ||
end | ||
self.replace(hsh) | ||
end | ||
|
||
end | ||
|
||
module HashOperators # :nodoc: | ||
|
||
# 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} | ||
# | ||
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 | ||
|
||
end | ||
|
||
end | ||
end | ||
|
||
|
||
class Hash # :nodoc: | ||
include Net::DNS::HashKeys | ||
include Net::DNS::HashOperators | ||
end |
Oops, something went wrong.