From: lamont@... Date: 2021-01-15T21:26:47+00:00 Subject: [ruby-core:102107] [Ruby master Bug#17545] Calling dup on a subclass of Proc returns a Proc and not the subclass Issue #17545 has been reported by lamont (Lamont Granquist). ---------------------------------------- Bug #17545: Calling dup on a subclass of Proc returns a Proc and not the subclass https://bugs.ruby-lang.org/issues/17545 * Author: lamont (Lamont Granquist) * Status: Open * Priority: Normal * 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: