[ruby/set] Fix ^ to respect subclasses

f88ecdef6b
This commit is contained in:
Kouhei Yanagita 2024-11-29 11:10:07 +09:00 committed by Hiroshi SHIBATA
parent f2334cf4b1
commit ae59b44041
2 changed files with 6 additions and 1 deletions

View file

@ -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