Sha256: b2ad20f2563ba49a9640b6c6615b8e74bb03ef0f5c3596780a4a45a7a370eaf5

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

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 = {}
        each do |key, val|
          hsh[key.downcase] = val
        end
        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.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

1 entries across 1 versions & 1 rubygems

Version Path
net-dns-0.9.0 lib/net/dns/core_ext.rb