Project

General

Profile

Actions

Bug #17545

closed

Calling dup on a subclass of Proc returns a Proc and not the subclass

Added by lamont (Lamont Granquist) almost 4 years ago. Updated almost 3 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
[ruby-core:102107]

Description

Trivial example:

[1] pry(main)> class Test < Proc; end
=> nil
[3] pry(main)> Test.new { puts "foo" }.dup
=> #<Proc:0x00007f91a78913c8 (pry):3>

Also fairly trivial workaround:

[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
=> #<Test:0x00007f91b8e73e38 (pry):9>

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0