Options: ensure copies do not share the underlying collection

This commit is contained in:
Jack Nagel 2013-08-22 11:46:47 -05:00
parent 7654077752
commit 9b2e04593f
2 changed files with 11 additions and 0 deletions

View File

@ -54,6 +54,11 @@ class Options
@options = Set.new(*args)
end
def initialize_copy(other)
super
@options = @options.dup
end
def each(*args, &block)
@options.each(*args, &block)
end

View File

@ -152,4 +152,10 @@ class OptionsTests < Test::Unit::TestCase
debug = Option.new("-d")
assert_equal [verbose, debug].sort, Options.coerce(array).to_a.sort
end
def test_copies_do_not_share_underlying_collection
copy = @options.dup << Option.new("foo")
assert_empty @options
assert_equal 1, copy.count
end
end