Sha256: c1551214f77e54d16cab040bc4a1e6ef8ecc8872f35f636b22d1e5d929542a97

Contents?: true

Size: 577 Bytes

Versions: 1

Compression:

Stored size: 577 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

      self
    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))

      self
    end

    def to_h
      @heads
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trav3-0.2.0 lib/trav3/headers.rb