Class: Rack::Utils::HeaderHash
- Defined in:
- lib/gems/rack-0.4.0/lib/rack/utils.rb
Overview
A case-normalizing Hash, adjusting on [] and []=.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #capitalize(k) ⇒ Object
-
#initialize(hash = {}) ⇒ HeaderHash
constructor
A new instance of HeaderHash.
- #to_hash ⇒ Object
Methods inherited from Hash
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_hash ⇒ Object
164 165 166 |
# File 'lib/gems/rack-0.4.0/lib/rack/utils.rb', line 164 def to_hash {}.replace(self) end |