From: Phillip Hutchings Date: 2006-07-26T05:57:13+09:00 Subject: Re: "Self" confusion On 7/26/06, Rimantas Liubertas wrote: > > Now I am fully confused! How do you define methods inside an instance > > of an object? Just like that ;) Pick up a copy of Programming Ruby, it's got a better explanation than I could come up with. Basically when you do: x = Object.new def x.foo 'bar' end you're added a singleton class on to x that contains the instance method foo. Only x can use this, no other Object instance will have it. So likewise when you're in an instance of Object, as ruby scripts start out in, self.foo is creating an instance method in the singleton class of the Object instance. -- Phillip Hutchings http://www.sitharus.com/