On 7/4/07, dblack / wobblini.net <dblack / wobblini.net> wrote: > Hi -- > > On Wed, 4 Jul 2007, Gregory Brown wrote: > > > On 7/4/07, Peñá, Botp <botp / delmonte-phil.com> wrote: > >> Fr David Black: > >> # Method definitions always have their own local scope, so a, b, and > >> # string are strictly local to the method. Blocks pick up the scope > >> # that they're created in, and can also create variables that weren't > >> # already in that scope. Those variables disappear when the block > >> # exits; the ones that were there already survive: > >> # > >> # x = 1 > >> # some_method { y = x + 1 } # same x; new y > >> # y # undefined; block's y didn't survive > >> # x # same x > >> > >> Hi David, > >> > >> How about parameter variables, will its scoping change/stay in ruby2 ? > >> > >> Currently, > >> > >> irb(main):011:0> x="testing" > >> => "testing" > >> irb(main):012:0> 5.times{|x|} > >> => 5 > >> irb(main):013:0> x > >> => 4 > >> > >> i'd prefer > >> > >> x = "testing" > >> some_method { |x| y = x + 1 } # different x; overrides any x > >> x # => "testing", same x outside > >> > > > > Hi, example from Eigenclass[0]: > > > > a = 1 > > 10.times{|a| } # !> shadowing outer local variable - a > > a # => 1 > > > > looks like it throws a warning and behaves as we all want it to. :) > > I actually like the current behavior, but I think I'm in a minority of > two (me and Guy Decoux, as I recall). No three, I guess I have very, very timidely said so, one day, I should have shouted loudly ;). Well that will not change the whole thing :( > I don't like the warning thing. > If the whole point is to make life easy for people who cut-and-paste > code blocks and don't want to check the names of the variables (which > I don't do, but I gather that's what people want to do), then it > should be totally ignored. A warning means you have to go in and > change it, which is what you have to do now. So I don't see any gain. > > > David > > -- > * Books: > RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) > -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck