Sha256: 55cc69e3cf9ae610c6f9db12ed98d10fcf2e30156b5c0bca7ebccd4a47bdb217

Contents?: true

Size: 553 Bytes

Versions: 2

Compression:

Stored size: 553 Bytes

Contents

require 'forwardable'

module Trav3
  class Headers
    extend Forwardable
    def_delegators :@heads, :each_pair

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

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

      for (key, value) in args
        @heads[key] = value
      end
    end

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

    def +(other)
      raise ArgumentError, "Invalid type provided." unless other.is_a?(Headers)
      @heads.merge(other.instance_variable_get(:@heads))
    end

    def to_h
      @heads
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trav3-0.1.1 lib/trav3/headers.rb
trav3-0.1.0 lib/trav3/headers.rb