Sha256: 1784aae94054057b6fe8e70f889af4ad9944de07fa092d72f556b7c81c9a9761
Contents?: true
Size: 721 Bytes
Versions: 2
Compression:
Stored size: 721 Bytes
Contents
module Trav3 class Options def initialize(**args) build(**args) end def opts if @opts.empty? "" else "?#{@opts.join('&')}" end end def build(**args) @opts ||= [] for (key, value) in args remove(key) @opts.push("#{key}=#{value}") end end def remove(key) @opts = @opts.keep_if {|item, _| !(/^#{key}=/ === "#{item}") } end def +(other) raise ArgumentError, "Invalid type provided." unless other.is_a?(Options) @opts += other.instance_variable_get(:@opts) end def to_s opts end def to_h @opts.map {|item| item.split("=") }.to_h end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
trav3-0.1.1 | lib/trav3/options.rb |
trav3-0.1.0 | lib/trav3/options.rb |