# Where nested methods go?

**URL:** <https://www.ruby-forum.com/t/where-nested-methods-go/115301>\
**Category:** Ruby\
**Created:** [September 23, 2007, 2:23pm UTC](https://www.ruby-forum.com/t/where-nested-methods-go/115301 "2007-09-23T14:23:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nibble70](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@nibble70](https://www.ruby-forum.com/u/nibble70)\
**Post date:** [September 23, 2007, 2:23pm UTC](https://www.ruby-forum.com/t/where-nested-methods-go/115301/1 "2007-09-23T14:23:12Z")

</div>

Hi,  
I’m very new to ruby, so please forgive me if my question seems somehow  
silly.  
I typed the following code:

class Myclass  
def m1  
def m2  
puts “m2”  
end  
end  
end

a = Myclass.new  
a.m1  
a.m2

b = Myclass.new  
b.m2

which gives the following output:

m1  
m2

While it is clear to me where the m1 method goes (that is: in the class  
object referred by Myclass constant) I’m a bit confused on why also m2  
is in Myclass class object!

I need some clarifications about it…

tahnks!  
Pietro

---

<div class="post-metadata">

**Author:** ![nibble70](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@nibble70](https://www.ruby-forum.com/u/nibble70)\
**Post date:** [September 23, 2007, 2:43pm UTC](https://www.ruby-forum.com/t/where-nested-methods-go/115301/2 "2007-09-23T14:43:25Z")

</div>

Pietro M. wrote:

> While it is clear to me where the m1 method goes (that is: in the class  
> object referred by Myclass constant) I’m a bit confused on why also m2  
> is in Myclass class object!

This question was thoroughly discussed in this thread:

[http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/8f4f9b54e86486b5/b9b44e4fc8d19429?lnk=gst&q=nested+methods&rnum=2#b9b44e4fc8d19429](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/8f4f9b54e86486b5/b9b44e4fc8d19429?lnk=gst&q=nested+methods&rnum=2#b9b44e4fc8d19429)

---

<div class="post-metadata">

**Author:** ![nibble70](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/74df32/32.png) [@nibble70](https://www.ruby-forum.com/u/nibble70)\
**Post date:** [September 23, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/where-nested-methods-go/115301/3 "2007-09-23T14:54:46Z")

</div>

Thanks! I will have a look at that!  
Pietro

Tim H. wrote:

> Pietro M. wrote:
> 
> > While it is clear to me where the m1 method goes (that is: in the class  
> > object referred by Myclass constant) I’m a bit confused on why also m2  
> > is in Myclass class object!
> 
> This question was thoroughly discussed in this thread:
> 
> [http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/8f4f9b54e86486b5/b9b44e4fc8d19429?lnk=gst&q=nested+methods&rnum=2#b9b44e4fc8d19429](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/8f4f9b54e86486b5/b9b44e4fc8d19429?lnk=gst&q=nested+methods&rnum=2#b9b44e4fc8d19429)
