# Module.nesting for anonymous modules?

**URL:** <https://www.ruby-forum.com/t/module-nesting-for-anonymous-modules/153351>\
**Category:** Ruby\
**Created:** [November 15, 2008, 11:20am UTC](https://www.ruby-forum.com/t/module-nesting-for-anonymous-modules/153351 "2008-11-15T11:20:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [November 15, 2008, 11:20am UTC](https://www.ruby-forum.com/t/module-nesting-for-anonymous-modules/153351/1 "2008-11-15T11:20:10Z")

</div>

Hi list,

I’m trying to get a reference to the module that a method is defined in,  
problem being that the module is generated dynamically so is not part of  
the  
AST.

foo = Module.new do  
def m  
Module.nesting  
end  
end  
=\> #Module:0x28879c4

c = Class.new { include foo }  
=\> #Class:0x287164c

c.new.m  
=\> []

Is there any way for a method defined like this to get a reference to  
its  
containing module?
