Class: Trav3::Headers
- Inherits:
-
Object
- Object
- Trav3::Headers
- Extended by:
- Forwardable
- Defined in:
- lib/trav3/headers.rb
Instance Method Summary collapse
-
#+(other) ⇒ Headers
Add the values of one
Headers
into another. -
#build(args = {}) ⇒ Headers
Add or update the request headers.
-
#initialize(args = {}) ⇒ Headers
constructor
A new instance of Headers.
-
#remove(key) ⇒ String, ...
Remove key/value from headers via key.
-
#to_h ⇒ Hash
Hash of the
Headers
.
Constructor Details
#initialize(args = {}) ⇒ Headers
Returns a new instance of Headers.
10 11 12 |
# File 'lib/trav3/headers.rb', line 10 def initialize(args = {}) build(args) end |
Instance Method Details
#+(other) ⇒ Headers
Add the values of one Headers
into another
39 40 41 42 43 44 45 |
# File 'lib/trav3/headers.rb', line 39 def +(other) raise TypeError, "Headers type expected, #{other.class} given" unless other.is_a? Headers @heads.merge(other.instance_variable_get(:@heads)) self end |
#build(args = {}) ⇒ Headers
Add or update the request headers
17 18 19 20 21 22 23 24 25 |
# File 'lib/trav3/headers.rb', line 17 def build(args = {}) @heads ||= {} args.each do |(key, value)| @heads[key] = value end self end |
#remove(key) ⇒ String, ...
Remove key/value from headers via key
31 32 33 |
# File 'lib/trav3/headers.rb', line 31 def remove(key) @heads.delete(key) end |
#to_h ⇒ Hash
Returns hash of the Headers
.
48 49 50 |
# File 'lib/trav3/headers.rb', line 48 def to_h @heads end |