From: "David A. Black" Date: 2009-07-06T00:08:31+09:00 Subject: Re: to_proc and Proc/block conversion with & Hi -- On Sun, 5 Jul 2009, Bertram Scharpf wrote: > Hi, > > Am Sonntag, 05. Jul 2009, 19:51:28 +0900 schrieb David A. Black: >> On Sun, 5 Jul 2009, Joel VanderWerf wrote: >>> Russ McBride wrote: >>> >>> constructing a Proc using &: >>> >>> def map(&b) >>> b.call ... >>> end >>> >>> or equivalently with Proc.new: >>> >>> def map >>> b = Proc.new >>> b.call >>> end >> >> That's not going to access the caller's code, though, since you're >> creating a totally new Proc. > > Sorry, but these are not the same: > > Proc.new > Proc.new { } > > Try this: > > def f ; Proc.new ; end > p = f { "hello" } > p.call > #=> "hello" How odd. I wonder what the point of that is. I'd rather be warned if I write Proc.new without a block, than have it default to the code block. But you're right that I'm wrong in correcting Joel. Rewind. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) Training! Intro to Ruby, with Black & Kastner, September 14-17 (More info: http://rubyurl.com/vmzN)