summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-11-02 05:45:12 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-11-02 05:45:12 +0000
commite3ed0b4db2f1420e524056bf2b86e8a561e5cb09 (patch)
tree3ae9f61f30b03b7554492bcf38418dcc77403641 /lib
parent0f125b5c927d69063ed1e99b12622507956554d3 (diff)
downloadruby-e3ed0b4db2f1420e524056bf2b86e8a561e5cb09.tar.gz
ruby-e3ed0b4db2f1420e524056bf2b86e8a561e5cb09.tar.xz
ruby-e3ed0b4db2f1420e524056bf2b86e8a561e5cb09.zip
* lib/set.rb (Set#^): Fix XOR operation against a container that
holds duplicate values. [issue: #6444] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/set.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/set.rb b/lib/set.rb
index ace02e08f..66ffc898a 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -294,8 +294,8 @@ class Set
# and the given enumerable object. (set ^ enum) is equivalent to
# ((set | enum) - (set & enum)).
def ^(enum)
- 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
@@ -1039,6 +1039,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]