Class: Excon::Headers
- Inherits:
-
Hash
- Object
- Hash
- Excon::Headers
- Defined in:
- lib/excon/headers.rb
Constant Summary collapse
- SENTINEL =
{}
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object (also: #store)
- #assoc(obj) ⇒ Object
- #delete(key, &proc) ⇒ Object
- #fetch(key, default = nil, &proc) ⇒ Object
- #has_key?(key) ⇒ Boolean (also: #key?, #member?)
-
#initialize ⇒ Headers
constructor
A new instance of Headers.
- #merge(other_hash) ⇒ Object
- #merge!(other_hash) ⇒ Object
- #raw_assoc ⇒ Object
- #raw_delete ⇒ Object
- #raw_fetch ⇒ Object
- #raw_has_key? ⇒ Object
- #raw_merge ⇒ Object
- #raw_merge! ⇒ Object
- #raw_reader ⇒ Object
- #raw_rehash ⇒ Object
- #raw_values_at ⇒ Object
- #raw_writer ⇒ Object
- #rehash ⇒ Object
- #values_at(*keys) ⇒ Object
Constructor Details
#initialize ⇒ Headers
Returns a new instance of Headers.
24 25 26 27 |
# File 'lib/excon/headers.rb', line 24 def initialize super @downcased = {} end |
Instance Method Details
#[](key) ⇒ Object
29 30 31 |
# File 'lib/excon/headers.rb', line 29 def [](key) @downcased[key.to_s.downcase] end |
#[]=(key, value) ⇒ Object Also known as: store
33 34 35 36 |
# File 'lib/excon/headers.rb', line 33 def []=(key, value) raw_writer(key, value) @downcased[key.to_s.downcase] = value end |
#assoc(obj) ⇒ Object
40 41 42 |
# File 'lib/excon/headers.rb', line 40 def assoc(obj) @downcased.assoc(obj.downcase) end |
#delete(key, &proc) ⇒ Object
45 46 47 48 |
# File 'lib/excon/headers.rb', line 45 def delete(key, &proc) raw_delete(key, &proc) @downcased.delete(key.to_s.downcase, &proc) end |
#fetch(key, default = nil, &proc) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/excon/headers.rb', line 50 def fetch(key, default = nil, &proc) if proc @downcased.fetch(key.to_s.downcase, &proc) else @downcased.fetch(key.to_s.downcase, default) end end |
#has_key?(key) ⇒ Boolean Also known as: key?, member?
58 59 60 |
# File 'lib/excon/headers.rb', line 58 def has_key?(key) raw_key?(key) || @downcased.has_key?(key.to_s.downcase) end |
#merge(other_hash) ⇒ Object
64 65 66 |
# File 'lib/excon/headers.rb', line 64 def merge(other_hash) self.dup.merge!(other_hash) end |
#merge!(other_hash) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/excon/headers.rb', line 68 def merge!(other_hash) other_hash.each do |key, value| self[key] = value end raw_merge!(other_hash) end |
#raw_assoc ⇒ Object
10 |
# File 'lib/excon/headers.rb', line 10 alias_method :raw_assoc, :assoc |
#raw_delete ⇒ Object
12 |
# File 'lib/excon/headers.rb', line 12 alias_method :raw_delete, :delete |
#raw_fetch ⇒ Object
13 |
# File 'lib/excon/headers.rb', line 13 alias_method :raw_fetch, :fetch |
#raw_has_key? ⇒ Object
14 |
# File 'lib/excon/headers.rb', line 14 alias_method :raw_has_key?, :has_key? |
#raw_merge ⇒ Object
18 |
# File 'lib/excon/headers.rb', line 18 alias_method :raw_merge, :merge |
#raw_merge! ⇒ Object
19 |
# File 'lib/excon/headers.rb', line 19 alias_method :raw_merge!, :merge! |
#raw_reader ⇒ Object
8 |
# File 'lib/excon/headers.rb', line 8 alias_method :raw_reader, :[] |
#raw_rehash ⇒ Object
20 |
# File 'lib/excon/headers.rb', line 20 alias_method :raw_rehash, :rehash |
#raw_values_at ⇒ Object
22 |
# File 'lib/excon/headers.rb', line 22 alias_method :raw_values_at, :values_at |
#raw_writer ⇒ Object
7 |
# File 'lib/excon/headers.rb', line 7 alias_method :raw_writer, :[]= |
#rehash ⇒ Object
75 76 77 78 |
# File 'lib/excon/headers.rb', line 75 def rehash @downcased.rehash raw_rehash end |
#values_at(*keys) ⇒ Object
80 81 82 |
# File 'lib/excon/headers.rb', line 80 def values_at(*keys) @downcased.values_at(*keys.map {|key| key.to_s.downcase}) end |