Class: Requests::CIHash
- Inherits:
-
Object
- Object
- Requests::CIHash
- Includes:
- Enumerable
- Defined in:
- lib/requests/structures.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #delete(k) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(h = nil) ⇒ CIHash
constructor
A new instance of CIHash.
- #inspect ⇒ Object
- #key?(k) ⇒ Boolean (also: #include?, #has_key?)
- #keys ⇒ Object
- #merge!(o) ⇒ Object
- #size ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(h = nil) ⇒ CIHash
Returns a new instance of CIHash.
6 7 8 9 |
# File 'lib/requests/structures.rb', line 6 def initialize(h = nil) @d = {} h && h.each { |k, v| self[k] = v } end |
Instance Method Details
#[](k) ⇒ Object
14 15 16 17 |
# File 'lib/requests/structures.rb', line 14 def [](k) e = @d[k.to_s.downcase] e ? e[1] : nil end |
#[]=(k, v) ⇒ Object
10 11 12 13 |
# File 'lib/requests/structures.rb', line 10 def []=(k, v) @d[k.to_s.downcase] = [k.to_s, v] v end |
#delete(k) ⇒ Object
23 24 25 26 |
# File 'lib/requests/structures.rb', line 23 def delete(k) e = @d.delete(k.to_s.downcase) e ? e[1] : nil end |
#each ⇒ Object
27 28 29 30 |
# File 'lib/requests/structures.rb', line 27 def each return enum_for(:each) unless block_given? @d.each_value { |k, v| yield k, v } end |
#empty? ⇒ Boolean
39 40 41 |
# File 'lib/requests/structures.rb', line 39 def empty? @d.empty? end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/requests/structures.rb', line 49 def inspect to_h.inspect end |
#key?(k) ⇒ Boolean Also known as: include?, has_key?
18 19 20 |
# File 'lib/requests/structures.rb', line 18 def key?(k) @d.key?(k.to_s.downcase) end |
#keys ⇒ Object
31 32 33 |
# File 'lib/requests/structures.rb', line 31 def keys @d.values.map(&:first) end |
#merge!(o) ⇒ Object
45 46 47 48 |
# File 'lib/requests/structures.rb', line 45 def merge!(o) o&.each { |k, v| self[k] = v } self end |
#size ⇒ Object
42 43 44 |
# File 'lib/requests/structures.rb', line 42 def size @d.size end |
#to_h ⇒ Object
34 35 36 37 38 |
# File 'lib/requests/structures.rb', line 34 def to_h h = {} @d.each_value { |k, v| h[k] = v } h end |