diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-11-02 05:52:12 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-11-02 05:52:12 +0000 |
commit | 30065371d1fa1acb4278f35e984f4fc04eae562b (patch) | |
tree | 5b98492e74a87b5e7d2cd8b76d382f39dcd7d9ba /lib/set.rb | |
parent | 3963aaa75b77ea2311f57fa99781f7abb6e11862 (diff) |
* lib/set.rb (Set#^): Fix XOR operation against a container that
holds duplicate values. [issue: #6444]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r-- | lib/set.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/set.rb b/lib/set.rb index 0ad47c842f..e244712833 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -301,8 +301,8 @@ class Set # ((set | enum) - (set & enum)). def ^(enum) enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable" - n = dup - enum.each { |o| if n.include?(o) then n.delete(o) else n.add(o) end } + n = Set.new(enum) + each { |o| if n.include?(o) then n.delete(o) else n.add(o) end } n end @@ -1049,6 +1049,13 @@ class TC_Set < Test::Unit::TestCase assert_equal(Set[2,4], ret) end + def test_xor + set = Set[1,2,3,4] + ret = set ^ [2,4,5,5] + assert_not_same(set, ret) + assert_equal(Set[1,3,5], ret) + end + def test_eq set1 = Set[2,3,1] set2 = Set[1,2,3] |