Class: Trav3::Headers

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/trav3/headers.rb

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Headers

Returns a new instance of Headers


8
9
10
# File 'lib/trav3/headers.rb', line 8

def initialize(**args)
  build(**args)
end

Instance Method Details

#+(other) ⇒ Object

Raises:

  • (TypeError)

26
27
28
29
30
31
32
# File 'lib/trav3/headers.rb', line 26

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) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'lib/trav3/headers.rb', line 12

def build(**args)
  @heads ||= {}

  args.each do |(key, value)|
    @heads[key] = value
  end

  self
end

#remove(key) ⇒ Object


22
23
24
# File 'lib/trav3/headers.rb', line 22

def remove(key)
  @heads.delete(key)
end

#to_hObject


34
35
36
# File 'lib/trav3/headers.rb', line 34

def to_h
  @heads
end