diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 17:03:40 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 17:03:40 +0000 |
commit | 0fcac8f1a35b73713849db323c206fb4f9aeda5a (patch) | |
tree | 8ed0777559edacdce9e031513419993c4296562c | |
parent | d02211c9da608742b09aec768db79442007eabc0 (diff) |
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
-rw-r--r-- | lib/set.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/set.rb b/lib/set.rb index 05eb3ffb2a..b668738ebb 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -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! |