From: Joel VanderWerf Date: 2004-06-02T05:23:30+09:00 Subject: Re: Blocks and Closures 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