# Context of self

**URL:** <https://www.ruby-forum.com/t/context-of-self/156749>\
**Category:** Ruby\
**Created:** [January 2, 2009, 11:15am UTC](https://www.ruby-forum.com/t/context-of-self/156749 "2009-01-02T11:15:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [January 2, 2009, 11:15am UTC](https://www.ruby-forum.com/t/context-of-self/156749/1 "2009-01-02T11:15:45Z")

</div>

Hi  
I tried like

class First  
def initialize  
puts ‘in First class’+self.inspect  
end  
end  
class Second \< First  
def initialize  
super  
puts ‘in second class’+self.inspect  
end  
end

Second.new  
I got result as  
in First class#Second:0xb7f61820  
in second class#Second:0xb7f61820

```
     So is #<Second:0xb7f61820> always means from where I call the

```

def? I did not understand it

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [January 2, 2009, 11:51am UTC](https://www.ruby-forum.com/t/context-of-self/156749/2 "2009-01-02T11:51:51Z")

</div>

Sijo Kg wrote:

> Second.new  
> Â Â Â Â I got result as  
> in First class#Second:0xb7f61820  
> in second class#Second:0xb7f61820
> 
> Â Â Â Â Â So is #Second:0xb7f61820 always means from where I call the  
> def? I did not understand it

self is the current object (in this case the object just constructed by  
new).  
The output of inspect does not change depending on where inspect is  
called  
from, nor does the value of self change when you call super.  
In other words: if you call self.inspect and self is an object of class  
Second, you’ll call Second#inspect which, unless overridden, will return  
“#Second:bla”, and if you call Second.new, self will indeed be an  
object  
of class Second.

HTH,  
Sebastian
