ts <decoux / moulon.inra.fr> wrote: > > >>>>> "B" == Ben Tilly <ben_tilly / hotmail.com> writes: > >B> in Perl. By itself this is useful as a way of telling >B> Ruby that I don't care if there is already something in >B> scope called foo, this foo is private. > > Like I've said previously I think this is easy to do (just re-use a >keyword like `do' to don't break old scripts), but finally you end up with >something that is difficult to understand. I should follow up by noting that it is unwise to plan on there being another foo in scope. :-) > Just an example > >pigeon% cat b.rb >#!./ruby >def toto(a) > p "1 #{a}" > do(a = a - 2, b = 2) > p "2 #{a}, #{b}" > do a = a + 2, b = a + 10 > p "3 #{a}, #{b}" > [4].each do |a| > p "3' #{a}" > end > p "3 #{a}, #{b}" > end > p "4 #{a}, #{b}" > end > p "5 #{a}" >end >toto(12) >pigeon% > >pigeon% b.rb >"1 12" >"2 10, 2" >"3 12, 20" >"3' 4" >"3 4, 20" >"4 10, 2" >"5 12" >pigeon% > > If you really understand this script (when you read it), you are lucky >:-) > It isn't that complex. You just created a series of variables named a and b while printing, and then you backed out of the stack and it reversed. The only exception to that pattern is that when you assigned to a by using it as an argumet in the middle of the script, you didn't create another variable. So there is a slight asymmetry. In any case my point is to get code which you can look at locally and verify what it does, without having to worry about any possible action at a distance. Cheers, Ben _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com