1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Avoid use of self.class.new(self) in Set#collect!

That prevents infinite recursion when a subclass of Set uses
`collect!` in its constructor.

This should fix [Bug #12437].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2017-10-21 17:03:40 +00:00
parent d02211c9da
commit 0fcac8f1a3

View file

@ -378,7 +378,9 @@ class Set
# Returns an enumerator if no block is given.
def collect!
block_given? or return enum_for(__method__) { size }
replace(self.class.new(self) { |o| yield(o) })
set = self.class.new
each { |o| set << yield(o) }
replace(set)
end
alias map! collect!