Project

General

Profile

Actions

Bug #11160

closed

Subclasses of Proc converted when passed to a block

Added by alextyu (Alex Yu) almost 9 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

As Subclasses of Proc are passed as-is when sent to methods as blocks, it would be expected that the same behavior occurs when passing such a subclass of Proc to a block. However, Ruby's block.call somehow converts the block to a Proc, losing the passed subclass. Is this a bug, or is there a particular reason for this design?

Here is an example:

class MyClass < Proc
end
=> nil

def foo (&x)
p x.class
end
=> :foo

x = Proc.new {|&x| p x.class}
=> #Proc:0x007faf0b042f60@(irb):77

z = MyClass.new {}
=> #MyClass:0x007faf0b0393c0@(irb):78

foo &z
MyClass
=> MyClass

x.call &z
Proc
=> Proc

Actions

Also available in: Atom PDF

Like0
Like0