class Rack::Utils::HeaderHash - rack-1.6.2 Documentation

# class Rack::Utils::HeaderHash

A case-insensitive Hash that preserves the original case of a header when set.

### Public Class Methods

new(hash={}) click to toggle source
Calls superclass method

    # File lib/rack/utils.rb, line 481
    def initialize(hash={})
      super()
      @names = {}
      hash.each { |k, v| self[k] = v }
    end

new(hash={}) click to toggle source
Calls superclass method

    # File lib/rack/utils.rb, line 477
    def self.new(hash={})
      HeaderHash === hash ? hash : super(hash)
    end

### Public Instance Methods

[](k) click to toggle source
Calls superclass method

    # File lib/rack/utils.rb, line 499
    def [](k)
      super(k) || super(@names[k.downcase])
    end

[]=(k, v) click to toggle source
Calls superclass method

    # File lib/rack/utils.rb, line 503
    def []=(k, v)
      canonical = k.downcase
      delete k if @names[canonical] && @names[canonical] != k # .delete is expensive, don't invoke it unless necessary
      @names[k] = @names[canonical] = k
      super k, v
    end

delete(k) click to toggle source
Calls superclass method

    # File lib/rack/utils.rb, line 510
    def delete(k)
      canonical = k.downcase
      result = super @names.delete(canonical)
      @names.delete_if { |name,| name.downcase == canonical }
      result
    end

each() { |k, respond_to?(:to_ary) ? to_ary.join("\n") : v| ... } click to toggle source
Calls superclass method

    # File lib/rack/utils.rb, line 487
    def each
      super do |k, v|
        yield(k, v.respond_to?(:to_ary) ? v.to_ary.join("\n") : v)
      end
    end

has_key?(k)
Alias for: include?
include?(k) click to toggle source

    # File lib/rack/utils.rb, line 517
    def include?(k)
      @names.include?(k) || @names.include?(k.downcase)
    end

Also aliased as: has_key?, member?, key?
key?(k)
Alias for: include?
member?(k)
Alias for: include?
merge(other) click to toggle source

    # File lib/rack/utils.rb, line 530
    def merge(other)
      hash = dup
      hash.merge! other
    end

merge!(other) click to toggle source

    # File lib/rack/utils.rb, line 525
    def merge!(other)
      other.each { |k, v| self[k] = v }
      self
    end

replace(other) click to toggle source

    # File lib/rack/utils.rb, line 535
    def replace(other)
      clear
      other.each { |k, v| self[k] = v }
      self
    end

to_hash() click to toggle source

    # File lib/rack/utils.rb, line 493
    def to_hash
      hash = {}
      each { |k,v| hash[k] = v }
      hash
    end