From: ko1@... Date: 2021-01-29T09:03:59+00:00 Subject: [ruby-core:102292] [Ruby master Bug#17545] Calling dup on a subclass of Proc returns a Proc and not the subclass Issue #17545 has been updated by ko1 (Koichi Sasada). Assignee set to ko1 (Koichi Sasada) Status changed from Open to Assigned This behavior is from ruby 1.9. Matz, is it a bug? ``` @all-ruby -e 'class Test < Proc; end; p Test.new { puts "foo" }.dup.class' :ok: 1.8 Test :ok: 1.9 -- 98e27016c9 (2021-01-29T07:22:12Z) Proc ``` ---------------------------------------- Bug #17545: Calling dup on a subclass of Proc returns a Proc and not the subclass https://bugs.ruby-lang.org/issues/17545#change-90147 * Author: lamont (Lamont Granquist) * Status: Assigned * Priority: Normal * Assignee: ko1 (Koichi Sasada) * ruby -v: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- Trivial example: ``` ruby [1] pry(main)> class Test < Proc; end => nil [3] pry(main)> Test.new { puts "foo" }.dup => # ``` Also fairly trivial workaround: ```ruby [4] pry(main)> class Test < Proc [4] pry(main)* def dup [4] pry(main)* self.class.new(&super) [4] pry(main)* end [4] pry(main)* end => :dup [5] pry(main)> Test.new { puts "foo" }.dup => # ``` Seems like a bug though, Proc#dup is probably calling the ruby-c equivalent of Proc.new rather than self.class.new and bypassing subclassing -- https://bugs.ruby-lang.org/ Unsubscribe: