From: Gregory Brown Date: 2007-07-04T22:52:26+09:00 Subject: Re: block params scoping (was ruby-talk 257917: RE: Using a block to surround a string?) On 7/4/07, Pe�a, Botp 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. :) Man, this list of changes is fun. :) -greg [0] http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l41