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?

Thanks!

On Wed, 2 Jun 2004 05:23:30 +0900, Joel VanderWerf
<vjoel / path.berkeley.edu> wrote:
> 
> 
> Alex McHale wrote:
> > If this is covered elsewhere, please point me in the right direction.
> >
> > Either why, my question is what exactly is the difference between a
> > block / closure of the syntax
> > do |x, y|
> >     ....
> > end
> >
> > versus
> >
> > {|x, y|
> >     ....
> > }
> >
> > Are these idioms identical in all but their syntax?  Or is there an
> > underlying difference to them?
> >
> > This has been bugging me for a while, and I haven't been able to
> > locate the answer in the docs I've found.
> 
> The only difference is precedence:
> 
> def foo(*args, &bl)
>    puts "foo got the block" if bl
> end
> 
> def bar(*args, &bl)
>    puts "bar got the block" if bl
> end
> 
> foo bar {}      # ==> bar got the block
> foo bar do end  # ==> foo got the block
> 
>