From: Michael Geary Date: 2004-07-10T01:47:31+09:00 Subject: Re: I love Ruby > > why are 'begin...end' and { } not always equivalent? Kaspar Schiess wrote: > This comes up once in a while, tell me if this answer is short enough: > [indentation added] > > def foo(arg=nil) > if block_given? > puts 'foo got block' > end > end > > def bar(arg=nil) > if block_given? > puts 'bar got block' > end > end > > foo bar do end # > foo got block > foo bar {} # > bar got block That is very helpful, thanks. One thing I don't understand: *Why* does it work this way? What is the purpose of having different precedence for {} and do...end? It's always seemed a bit confusing to me, so knowing the purpose for this distinction would help keep it straight. Thanks, -Mike