From: Dave Thomas Date: 2002-03-27T01:55:26+09:00 Subject: Re: Difference between 'do' and 'begin' Sean Middleditch writes: > On Tue, 2002-03-26 at 11:27, Kent Dahl wrote: > > james@rubyxml.com wrote: > > > However, both Ruby in a Nutshell and the Pickaxe book refer to > > > begin/end as blocks. > > > > Ouch... > > > > I've been thinking about this problem ever since I held a small > > introduction to Ruby earlier this month. I did my best to seperate the > > two concepts, but it seemed to confuse people nonetheless. We need a > > better name for the begin/end construct, and preferably something that > > helps us talk about "blocks of code" in contrast to Ruby blocks. Agreed - it's a bit of a mess. Andy and I took the conscious decision to try to use existing Ruby terminology and notations, so we used 'block' for both (and '#fred' for instance methods). In retrospect, this might not have been wise. However, a short term fix is not to teach begin/end until you get to exceptions. Then you can start by showing exception handling in methods: def fred .. rescue X => x .. end and do most of the exception work there. Then, as an afterthought, you could say "but what happens if we need to localize the handling of an exception to less than a method. Well, Ruby has an exception scoping mechanism, begin/end..." and go on from there. Dave (btw - I notice that the latest CVS also allows class Fred rescue X => x end Now that's a construct that'll see a lot of use :)