Class: Rack::Utils::HeaderHash
- Inherits:
-
Hash
- Object
- Hash
- Rack::Utils::HeaderHash
- Defined in:
- 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
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_hash ⇒ Object
102 103 104 |
# File 'lib/rack/utils.rb', line 102 def to_hash {}.replace(self) end |