From: Russ McBride Date: 2009-07-06T07:01:34+09:00 Subject: Re: to_proc and Proc/block conversion with & Thanks. Interesting discussion. > given &expr, if expr is a Proc object, use it as > the block; if not, call to_proc on it. ... and then use the resulting proc as a block. Maybe the best way to think of & is a a proc/block converter, which, if called on something that is neither looks first for a to_proc method before performing its conversion. The following seems quite surprising to me and I, too, would rather have a warning I think than this default behavior. def f ; Proc.new ; end p = f { "hello" } p.call #=> "hello" > 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 But, you could just do something like this, right? def defer(time, &some_block) if time < Time.now yield # or some_block.call else pr = some_block # store pr somewhere and schedule it for execution end end Cheers, Russ P.S. Joel, I seen now why you were inclined toward Rhodes. :-)