From: "Mauricio Fernández" Date: 2003-02-21T04:52:37+09:00 Subject: Re: proc {} vs. Method#to_proc On Fri, Feb 21, 2003 at 04:10:41AM +0900, Jim Freeze wrote: > On Friday, 21 February 2003 at 3:38:30 +0900, Eric Hodel wrote: > > Jim Freeze (jim@freeze.org) wrote: > > > > > On Friday, 21 February 2003 at 1:19:17 +0900, dblack@candle.superlink.net wrote: > > > > pr = Proc.new { puts "hi from anonymous Proc" } > > > > methproc = A.new.method(:talk).to_proc > > > > > > > > [1,2,3].each &pr # "hi from anonymous Proc\n" * 3 > > > > [1,2,3].each &methproc # in `talk': wrong # of arguments(1 for 0) > > > > > > Interesting. I would have just done > > > > > > [1,2,3].each { methproc.call } > > > > > > and never have noticed. Can you explain what is happening when > > > I replace {...} with &pr. > > > > & turns a proc into a block. > > So why the error wrong # of arguments? It seems that Method#to_proc works like class Method def my_to_proc proc { |*args| self.call(*args) } end end no matter what you pass the block, it won't complain, but at some point you actually call the method... In eval.c you have static VALUE bmcall(args, method) VALUE args, method; { args = svalue_to_avalue(args); return method_call(RARRAY(args)->len, RARRAY(args)->ptr, method); /* => this is the line responsible for the arity error if I'm right */ } static VALUE method_proc(method) VALUE method; { return rb_iterate((VALUE(*)_((VALUE)))mproc, 0, bmcall, method); } Read my other msg. for a quick "solution". -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com LILO, you've got me on my knees! -- David Black, dblack@pilot.njin.net, with apologies to Derek and the Dominos, and Werner Almsberger