From: Diogo Lisboa Date: 2008-11-28T09:57:11+09:00 Subject: [ruby-core:20144] Re: [Bug #797] bug or feature: local method ? On Wed, Nov 26, 2008 at 4:32 PM, Francoys wrote: > declaring variables inside a method that are accessibles to all the > nested methods. This isn't possible though. def foo bar = 10 def gazonk p bar end end >> gazonk # => undefined local variable or method `gazonk' >> foo # => nil >> gazonk # => undefined local variable or method `bar' This doesn't work because the chained method is in a whole new scope which doesn't know anything about the outer method's local variables. But, however odd this functionality is, I think it would be useful for the enclosing method to inherit the outer scope. You'd get something like named closures, and calling `gazonk' after `foo' would be able to print 10. However, this wouldn't be consistent, meaning, it should have to work if you declared a local variable in a class definition and all the methods would be aware of that; at this point, things get ugly. I think the idea of 'named closure' could be interesting (I don't know what consequences this would have, but sounds like a feature more than a bug). It beats returning lambdas in an array. Would you, enlightened ones, share your opinions on this? On the idea of the local methods being a bug or feature, I don't think they count much as a feature the way they currently are. Diogo