great readhttp://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Yesterday we were noticing how when you send a block to a method there was a difference b/w the block delimiters. Like:
method_name :some_object {block}
and
method_name :some_object do block end
I found jim wierich's response on http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
to be very helpful in understanding the way the ruby parser
The difference is where in the operator precedence table they fall. { } binds tighter than do/end.
For example:
f g { } is parsed as f(g { }), where the braces belong to the method g.
On the other hand, f g do end is parsed as f(g) do end, where the braces belong to the method f.
It only matters when you omit parenthesis and create ambiguities.
it's interesting to see how these paradigms are implemented: procs and lambdas as means to gain more duck typed secure code with control of side effects