From: "David A. Black" Date: 2004-08-21T22:31:04+09:00 Subject: Re: This naughty language of ours violates hallowed Structure Programming sophistries Hi -- On Sat, 21 Aug 2004, Phlip wrote: > Rubies: (I think of myself more as a Ruby*ist*, but so be it :-) > Ruby variables create into their method's scope, not their block's scope. > That's why the above code works - it tweaks the Structured Programming > rules. The element inside the if statement's blocks should, in theory, exit > scope and disappear before the last element. 'if' doesn't create a new scope, but code blocks do: $ ruby -e ' [1,2,3].each {|x| p x; y=1}; p x rescue puts $!; p y rescue puts $!' 1 2 3 undefined local variable or method `x' for main:Object undefined local variable or method `y' for main:Object So the method/block scope distinction doesn't generally hold. (This is among the areas under revision for 2.0... so stay tuned.) The "in theory" bit is a little damning, since it suggests that Ruby's design in this regard violates some general theory or principle, which I don't think it does. Having 'if' be of flat scope is a different *practice* than other languages, but I don't think there's any theoretical mandate to do it one way or the other. David -- David A. Black dblack@wobblini.net