# Uses of "self"?

**URL:** <https://www.ruby-forum.com/t/uses-of-self/204200>\
**Category:** Rails\
**Created:** [March 7, 2011, 6:51pm UTC](https://www.ruby-forum.com/t/uses-of-self/204200 "2011-03-07T18:51:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 7, 2011, 6:51pm UTC](https://www.ruby-forum.com/t/uses-of-self/204200/1 "2011-03-07T18:51:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gabaluschi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b3f665/32.png) [@gabaluschi](https://www.ruby-forum.com/u/gabaluschi)\
**Post date:** [March 7, 2011, 7:31pm UTC](https://www.ruby-forum.com/t/uses-of-self/204200/2 "2011-03-07T19:31:11Z")

</div>

On 7 Mar 2011, at 17:51, Gaba L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![gabaluschi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b3f665/32.png) [@gabaluschi](https://www.ruby-forum.com/u/gabaluschi)\
**Post date:** [March 7, 2011, 8:49pm UTC](https://www.ruby-forum.com/t/uses-of-self/204200/3 "2011-03-07T20:49:46Z")

</div>

> > 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.

> **[The Well-Grounded Rubyist - David A. Black](https://www.manning.com/books/the-well-grounded-rubyist)**
>
> The Well-Grounded Rubyist takes you from interested novice to proficient practitioner. It's a beautifully written tutorial that begins with the basic steps to get your first Ruby program up and running and goes on to explore sophisticated topics like...

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

-philip
