Sha256: 34d8408075ca1c8fd8be28cd10afd8488350e5fc8b6f165bdc70b2862957008a

Contents?: true

Size: 1 KB

Versions: 12

Compression:

Stored size: 1 KB

Contents

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

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
net-dns2-0.8.7 lib/net/dns/core_ext.rb
net-dns2-0.8.6 lib/net/dns/core_ext.rb
net-dns2-0.8.5 lib/net/dns/core_ext.rb
net-dns2-0.8.4 lib/net/dns/core_ext.rb
net-dns2-0.8.3 lib/net/dns/core_ext.rb
net-dns2-0.8.2 lib/net/dns/core_ext.rb
net-dns2-0.8.1 lib/net/dns/core_ext.rb
net-dns-0.8.0 lib/net/dns/core_ext.rb
net-dns-0.7.1 lib/net/dns/core_ext.rb
net-dns-0.7.0 lib/net/dns/core_ext.rb
net-dns-0.6.1 lib/net/dns/core_ext.rb
net-dns-0.6.0 lib/net/dns/core_ext.rb