From: Alex McHale Date: 2004-06-02T05:41:15+09:00 Subject: Re: Blocks and Closures Oooh I understand now. In fact I had given my own answer initially, by noting that bl is the proc object. Thank you for the clarification. I come to love Ruby more and more every day ... For me, Ruby is a lot like vim. I've been using it for years, and I still learn something new about it every day. On Wed, 2 Jun 2004 05:38:19 +0900, Joel VanderWerf wrote: > > Alex McHale wrote: > > Alright, while that is very confusing to me (not the concept, I > > understand what you said, just why the precedence is different), you > > raise another question. > > > > In your example, you use the &bl syntax. I understand that if you > > want the proc object, that is the syntax to use, but why use it in > > that case? > > > > Wouldn't this give identical results? > > > > def foo(*args) > > puts "foo got the block" if yield > > end > > > > etc? Is the reason to use this construct because you want to demand > > that a block be passed? > > > > And on that note, is there a syntax to determine whether or a block > > was passed to the method, in the syntax of my construct? > > You're right, there's no reason to use the &bl notation. You can use the > Kernel#block_given? method: > > def foo(*args) > puts "foo got the block" if block_given? > end > > But using 'if yield' is different: it tests the return value of the > block, not the existence of the block. > >