Class: Rack::Utils::HeaderHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/rack/utils.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ HeaderHash

Returns a new instance of HeaderHash.



98
99
100
# File 'lib/rack/utils.rb', line 98

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

Instance Method Details

#[](k) ⇒ Object



106
107
108
# File 'lib/rack/utils.rb', line 106

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

#[]=(k, v) ⇒ Object



110
111
112
# File 'lib/rack/utils.rb', line 110

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

#capitalize(k) ⇒ Object



114
115
116
# File 'lib/rack/utils.rb', line 114

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

#to_hashObject



102
103
104
# File 'lib/rack/utils.rb', line 102

def to_hash
  {}.replace(self)
end