[ruby/set] Fix ^ to respect subclasses
https://github.com/ruby/set/commit/f88ecdef6b
This commit is contained in:
parent
f2334cf4b1
commit
ae59b44041
@ -662,7 +662,7 @@ class Set
|
||||
# Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
|
||||
# Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
|
||||
def ^(enum)
|
||||
n = Set.new(enum)
|
||||
n = self.class.new(enum)
|
||||
each { |o| n.add(o) unless n.delete?(o) }
|
||||
n
|
||||
end
|
||||
|
@ -643,6 +643,11 @@ class TC_Set < Test::Unit::TestCase
|
||||
ret = set ^ [2,4,5,5]
|
||||
assert_not_same(set, 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
|
||||
|
||||
def test_eq
|
||||
|
Loading…
x
Reference in New Issue
Block a user