Options: ensure copies do not share the underlying collection
This commit is contained in:
parent
7654077752
commit
9b2e04593f
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user