Isn't the current behavior the same as using def self.foo?

For example:

class C
 def foo1
   def bar
     :bar
   end
 end

 def foo2
   def self.bar
     :bar
   end
 end
end

I haven't checked how the first case works internally, but my first
impression is that foo1 and foo2 would do precisely the same (only the
second form is somewhat more documented, being particularly common for
defining class methods).

If that's the case, I guess anyone who enjoys this feature could just
move to def object.method form. (Unless it'd also change meaning, of
course)


On Thu, Nov 27, 2008 at 22:57, Diogo Lisboa <diogoslisboa / gmail.com> wrote:
> 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.

Indeed, def (along with a few other constructions) defines its own
scope. And I personally consider that a feature, since you don't
declare the scope of a variable in Ruby and things could get messy
very easily.

Just my two cents.

--
Daniel