Class: Rack::Utils::HeaderHash

Inherits:
Hash show all
Defined in:
lib/gems/rack-0.9.1/lib/rack/utils.rb

Overview

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

Instance Method Summary collapse

Methods inherited from Hash

#getopt

Constructor Details

#initialize(hash = {}) ⇒ HeaderHash

Returns a new instance of HeaderHash.



162
163
164
165
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 162

def initialize(hash={})
  @names = {}
  hash.each { |k, v| self[k] = v }
end

Instance Method Details

#[](k) ⇒ Object



171
172
173
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 171

def [](k)
  super @names[k.downcase]
end

#[]=(k, v) ⇒ Object



175
176
177
178
179
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 175

def []=(k, v)
  delete k
  @names[k.downcase] = k
  super k, v
end

#delete(k) ⇒ Object



181
182
183
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 181

def delete(k)
  super @names.delete(k.downcase)
end

#include?(k) ⇒ Boolean Also known as: has_key?, member?, key?

Returns:

  • (Boolean)


185
186
187
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 185

def include?(k)
  @names.has_key? k.downcase
end

#merge(other) ⇒ Object



198
199
200
201
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 198

def merge(other)
  hash = dup
  hash.merge! other
end

#merge!(other) ⇒ Object



193
194
195
196
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 193

def merge!(other)
  other.each { |k, v| self[k] = v }
  self
end

#to_hashObject



167
168
169
# File 'lib/gems/rack-0.9.1/lib/rack/utils.rb', line 167

def to_hash
  {}.replace(self)
end