ruby-changes:48203
From: knu <ko1@a...>
Date: Sun, 22 Oct 2017 02:03:46 +0900 (JST)
Subject: [ruby-changes:48203] knu:r60317 (trunk): Avoid use of `self.class.new(self)` in Set#collect!
knu 2017-10-22 02:03:40 +0900 (Sun, 22 Oct 2017) New Revision: 60317 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60317 Log: 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]. Modified files: trunk/lib/set.rb Index: lib/set.rb =================================================================== --- lib/set.rb (revision 60316) +++ lib/set.rb (revision 60317) @@ -378,7 +378,9 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L378 # 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! -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/