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.

http://www.manning.com/black2/

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

-philip

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs