From: james@... Date: 2002-03-26T23:23:54+09:00 Subject: RE: Difference between 'do' and 'begin' > -----Original Message----- > From: Clemens Hintze [mailto:c.hintze@gmx.net] > Although there *are* two 'keywords' to open a block, but those are > 'do' and '{'. Both have different precedence, so that both following > lines have different meaning: > ... > > 'begin' is a totally different construct, that is *not* building a > block. It is more a statement like 'if' or 'while' ... > > - A block, e.g., can be converted into a closure. You cannot do this > with 'begin' started code. > - A block opens an own scope for variables that were created within > the block. And it reuse variables that were created outside. 'begin' > do *not* open a new scope. All variables crated within are > accessible outside. > > 'begin' is most often used together with its 'rescue' and/or 'ensure' > part to catch and handle exceptions that were raised by code within. However, both Ruby in a Nutshell and the Pickaxe book refer to begin/end as blocks. So, is it incorrect to refer to begin # some code end as a block? Or is it block, but not the same sort of block as: { |foo| # do something with foo } James > > Regards, > \cle > -- > Clemens Hintze mailto: c.hintze@gmx.net >