lib/trav3/options.rb in trav3-0.2.0 vs lib/trav3/options.rb in trav3-0.2.1

- old
+ new

@@ -13,26 +13,39 @@ end def build(**args) @opts ||= [] - for (key, value) in args + args.each do |(key, value)| remove(key) @opts.push("#{key}=#{value}") end self end def remove(key) - @opts = @opts.keep_if {|item, _| - !(/^#{key}=/ === "#{item}") - } + return_value = nil + + @opts = @opts.keep_if do |item, value| + if entry_match?(key, item) + return_value = value + false + else + true + end + end + + return_value end + def reset! + @opts = [] + end + def +(other) - raise ArgumentError, "Invalid type provided." unless other.is_a?(Options) + raise TypeError, "Options type expected, #{other.class} given" unless other.is_a? Options @opts += other.instance_variable_get(:@opts) self end @@ -40,9 +53,15 @@ def to_s opts end def to_h - @opts.map {|item| item.split("=") }.to_h + @opts.map { |item| item.split('=') }.to_h + end + + private + + def entry_match?(entry, item) + /^#{entry}=/.match? item.to_s end end end