From: Joel VanderWerf Date: 2009-07-06T03:47:25+09:00 Subject: Re: to_proc and Proc/block conversion with & David A. Black wrote: > 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. Maybe it should be deprecated in practice. It's not apparent what's going on, and rdoc can't pick it up (I presume?). It's usually better to be more explicit using 'def foo(&b)' or yield. The only use I can think of for this feature[1] is if you want to conditionally instantiate the Proc, as in: def defer time if time < Time.now yield else pr = Proc.new # store pr somewhere and schedule it for execution end end [1] ri Proc.new -------------------------------------------------------------- Proc::new Proc.new {|...| block } => a_proc Proc.new => a_proc From Ruby 1.8 ------------------------------------------------------------------------ Creates a new Proc object, bound to the current context. Proc::new may be called without a block only within a method with an attached block, in which case that block is converted to the Proc object. def proc_from Proc.new end proc = proc_from { "hello" } proc.call #=> "hello" -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407