From: Robert Dober Date: 2008-06-27T04:45:47+09:00 Subject: Re: A cleaner way to pass a block or proc On Thu, Jun 26, 2008 at 9:18 PM, ara.t.howard wrote: > > On Jun 26, 2008, at 12:44 PM, Robert Dober wrote: > >> That is what OP wanted IIANM, the nils raise an exception later on. >> Anyway I thought I had made it clear that your code is preferable but >> I feel that teaching what Proc::new is about, is part of our job here >> ;) > > > ah. btw - i did not know about the argumentless Proc::new so you achieved > your goal ;-) > > a @ http://codeforpeople.com/ > -- > we can deny everything, except that we have the possibility of being better. > simply reflect on that. > h.h. the 14th dalai lama > > > > > Great I will spell it out for OP Block::new takes implicitely the block you have passed to a method irb(main):001:0> def a irb(main):002:1> Proc::new.call irb(main):003:1> end => nil irb(main):004:0> a do 42 end => 42 However if there was no block passed to the method there will be an error irb(main):005:0> a ArgumentError: tried to create Proc object without a block from (irb):2:in `new' from (irb):2:in `a' This error was caught by my rescue clause in the line @notifiers << ( Proc::new rescue notifier ) But please again, Ara's code is better idiomatic Ruby, but just in case you stumble around Proc::new one day ;) HTH Robert -- http://ruby-smalltalk.blogspot.com/ --- AALST (n.) One who changes his name to be further to the front D.Adams; The Meaning of LIFF