From: Joao Pedrosa Date: 2007-01-11T18:12:10+09:00 Subject: Re: [ ruby-Bugs-7680 ] a block argument within a block which argument has the same name leaks Hi, > |> For your information, Ruby2 has explicit scoping in blocks. > |> > |> lambda {|a,b; v1, v2| ...} > |> > |> Variables a, b (parameters), v1 and v2 are local to the lambda block. > | > |And otherwise 1.9 still uses the 1.8 lexical scoping semantics, yes? > > Yes, other local variables are local to innermost surrounding block. > At least until I make a big decision. Why don't we let "Darwin" decide this? Here's my idea: - create another Kernel level method, called "scope", which created a Proc descendent (to keep backwards compatibility), and accepts a first parameter for the binding object (a la eval). The new scope method might accept the parameters you propose, as well. Ah, and the local variables declared in it remain local, unless it has a binding object to which it would bind the local variables. class Scope < Proc end Examples: a) scope {|a,b; v1, v2| ...} b) scope {|v1, v2| n = 10 } p n #error. unknown n c) scope(binding) {|v1, v2| n = 10 } p n #prints 10 Then backwards compatibility could be kept. Anyway, I don't know everything that has been discussed about this subject already, but I just needed to update some of my libraries because of probable scoping issues, and the sooner a fix to this appears, the better. :-) Because I still have a lot of library code that uses "anonymous functions" and that might possibly have some kind of issue. I still have more conversions ahead to protect code against "heisenbugs" caused by this. That's an idea to try to avoid the "bikeshed talks". hehe. :-) Cheers, Joao