From: Robert Dober Date: 2011-03-28T21:26:24+09:00 Subject: Re: How to get the value of a singleton class? On Mon, Mar 28, 2011 at 10:55 AM, Brian Candler wrote: > Robert Dober wrote in post #989410: > I think it *is* a design choice, because of the local variable/method > ambiguity. > > If "class" and "def" did not start a new scope, then a bareword like "x" > *might* be a local variable within a closure. It would be extremely > difficult to tell; you'd have to read the entire program source code > back to the beginning of the file (assuming that 'load' and 'require' > started a new scope, otherwise it would be completely impossible). That is a very good point, I have used closure based programming, and I have suffered from this. I however think that I could have done much better than I did. I missed some opportunities to refactor and introduce more abstraction. From this experience I conclude that this would be a "feature" to use with care and that care does not come as natural at first... Now if you have long modules you will run into the same kind of problem too. I do not think that Ruby can have a save barrier against that. However the parser could restrict closing over one level which could be overcome with constructs like this x=42 class A x=x def a; x end ... However I get lost, what *really* could be a closure, I feel, is class << x; .... end as we are often in metaprogramming context here. Cheers Robert > > With the current rules, given some code like > >   ... lots of previous stuff >   def foo >     x >   end > > you can tell by inspection of method foo alone that x *must* be a method > call within foo; it's definitely not a local variable. > > -- > Posted via http://www.ruby-forum.com/. > > -- The 1,000,000th fibonacci number contains '42' 2039 times; that is almost 30 occurrences more than expected (208988 digits). N.B. The 42nd fibonacci number does not contain '1000000' that is almost the expected 3.0e-06 times.