Class: Rack::Utils::HeaderHash

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

Overview

A case-normalizing Hash, adjusting on [] and []=.

Instance Method Summary collapse

Methods inherited from Hash

#getopt

Constructor Details

#initialize(hash = {}) ⇒ HeaderHash

Returns a new instance of HeaderHash.



160
161
162
# File 'lib/gems/rack-0.4.0/lib/rack/utils.rb', line 160

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

Instance Method Details

#[](k) ⇒ Object



168
169
170
# File 'lib/gems/rack-0.4.0/lib/rack/utils.rb', line 168

def [](k)
  super capitalize(k)
end

#[]=(k, v) ⇒ Object



172
173
174
# File 'lib/gems/rack-0.4.0/lib/rack/utils.rb', line 172

def []=(k, v)
  super capitalize(k), v
end

#capitalize(k) ⇒ Object



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

def capitalize(k)
  k.to_s.downcase.gsub(/^.|[-_\s]./) { |x| x.upcase }
end

#to_hashObject



164
165
166
# File 'lib/gems/rack-0.4.0/lib/rack/utils.rb', line 164

def to_hash
  {}.replace(self)
end