Uses of "self"?

When does “self” refer to an instance of the class or object, when is it
a user object and when is it used to define a class method? What’s the
difference?

On 7 Mar 2011, at 17:51, Gaba L. [email protected] wrote:

When does “self” refer to an instance of the class or object, when is it
a user object and when is it used to define a class method? What’s the
difference?

I don’t think the distinction you mention exists. If self is SomeClass
then def self.foo is the same as def SomeClass.foo, just more
convenient.

Fred

When does “self” refer to an instance of the class or object, when is it
a user object and when is it used to define a class method? What’s the
difference?

If you really want to dig into it, I’d highly recommend The
Well-Grounded Rubyist. Chapter 5 in particular.

No affiliation other than I was lucky enough to review it. Good stuff.

-philip