mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
parent
f2334cf4b1
commit
ae59b44041
2 changed files with 6 additions and 1 deletions
|
@ -662,7 +662,7 @@ class Set
|
||||||
# Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
|
# Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
|
||||||
# Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
|
# Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
|
||||||
def ^(enum)
|
def ^(enum)
|
||||||
n = Set.new(enum)
|
n = self.class.new(enum)
|
||||||
each { |o| n.add(o) unless n.delete?(o) }
|
each { |o| n.add(o) unless n.delete?(o) }
|
||||||
n
|
n
|
||||||
end
|
end
|
||||||
|
|
|
@ -643,6 +643,11 @@ class TC_Set < Test::Unit::TestCase
|
||||||
ret = set ^ [2,4,5,5]
|
ret = set ^ [2,4,5,5]
|
||||||
assert_not_same(set, ret)
|
assert_not_same(set, ret)
|
||||||
assert_equal(Set[1,3,5], ret)
|
assert_equal(Set[1,3,5], ret)
|
||||||
|
|
||||||
|
set2 = Set2[1,2,3,4]
|
||||||
|
ret2 = set2 ^ [2,4,5,5]
|
||||||
|
assert_instance_of(Set2, ret2)
|
||||||
|
assert_equal(Set2[1,3,5], ret2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_eq
|
def test_eq
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue