From: Aleks Kissinger Date: 2006-07-26T06:41:41+09:00 Subject: Re: "Self" confusion Oh, sorry, I slightly mis-read. Yes, you probably know most of that. Anyway, "new" is an instance method of the new object created, so I see what you are saying. .....oops On 7/25/06, Aleks Kissinger wrote: > Well, in both cases, it refers to an object. When you are in the > top-level of a class definition, "self" actually refers to the class > object. That is to say, the instance of Class your new class > definition creates. > > class Foo > puts self > puts self.class > end > > => Foo > => Class > > So using self adds a method to the object "self", which happens to be > an instance of class. ie. class methods. > > On 7/25/06, Leslie Viljoen wrote: > > Thanks everybody, this really helps! > > So top level is an Object singleton referenced through 'self'. > > > > I think I get it. > > > > Part of my problem was that 'self' refers to the enclosing class when > > using def self.x, but within the new function, self refers to an > > object. Very interesting. > > > > Les > > > > >