aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 17:03:40 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 17:03:40 +0000
commitd3153f6480f7b2d3466bef9509eca4e8d9fe0835 (patch)
tree8ed0777559edacdce9e031513419993c4296562c /lib
parente700687856e5c2ac9cb7181a3072ec93a37691e2 (diff)
downloadruby-d3153f6480f7b2d3466bef9509eca4e8d9fe0835.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/set.rb4
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!