From 0fcac8f1a35b73713849db323c206fb4f9aeda5a Mon Sep 17 00:00:00 2001 From: knu Date: Sat, 21 Oct 2017 17:03:40 +0000 Subject: [PATCH] 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 --- lib/set.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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!