Bug #10277
closedAmpersand to_proc issues
Description
I'm noticing weird inconsistencies when when returning a bound method in the #to_proc method when using &instance_object
. When returning the bound method from #to_proc, it'll raise an error ("wrong argument type AmpersandMethod (expected Proc) (TypeError)", AmpersandMethod being my class name). However, if I explicitly #to_proc the bound method, everything works as normal. I've attached a small ruby script showing the problem.
Files
Updated by Anonymous about 10 years ago
This seems correct to me. The &
operator expects to_proc
to return an actual Proc
. AmpersandMethod#to_proc
does not return a Proc
, it returns a Method
.
In other words,
puts yielder(&AmpersandMethod.new.method(:mapper))
puts a.map(&AmpersandMethod.new.method(:mapper))
here to_proc
on the given object returns a Proc
.
puts yielder(&AmpersandMethod.new)
puts a.map(&AmpersandMethod.new)
here to_proc
on the given object returns a Method
, not a Proc
.
Updated by nobu (Nobuyoshi Nakada) about 10 years ago
- Status changed from Open to Rejected
to_proc
must return a Proc
, not a Method
.
They are different.