Add set union to Options

This commit is contained in:
Jack Nagel 2014-02-27 14:22:42 -06:00
parent 96df4fe1da
commit b2ccbfe6af
2 changed files with 11 additions and 0 deletions

View File

@ -83,6 +83,10 @@ class Options
Options.new(@options & o)
end
def |(o)
Options.new(@options | o)
end
def *(arg)
@options.to_a * arg
end

View File

@ -126,6 +126,13 @@ class OptionsTests < Test::Unit::TestCase
assert_equal [foo], (@options & options).to_a
end
def test_set_union
foo, bar, baz = %w{foo bar baz}.map { |o| Option.new(o) }
options = Options.new << foo << bar
@options << foo << baz
assert_equal [foo, bar, baz].sort, (@options | options).to_a.sort
end
def test_coerce_with_options
assert_same @options, Options.coerce(@options)
end