From: Joel VanderWerf Date: 2004-03-04T08:36:30+09:00 Subject: Re: Why do inner methods count in outer scope? Hal Fulton wrote: > Joel VanderWerf wrote: > >>> Method definitions are scoped the same way as @variables; the new >>> method is added to the current instance. It doesn't matter if you do >>> it at the >> >> >> ^^^^^^^^ >> >> Not exactly. It can be added to the current class, if that is the scope: >> >> class A >> def foo >> def bar; p "BAR"; end >> end >> end > > > It's still the current instance. The current instance here happens > to be a class. That use of "current instance" is confusing to me. Maybe "current definition scope" would be better. Words are more confusing than code... class A def foo p self def bar; p "BAR"; end end end a = A.new a.foo # ==> # Inside #foo, self refers to the instance of A. Yet, as my previous example showed, the method was added as an instance method of class A, not as a method of object A or as a singleton method of the instance of A.