# Getting the module name with ObjectSpace

**URL:** <https://www.ruby-forum.com/t/getting-the-module-name-with-objectspace/89596>\
**Category:** Rails\
**Created:** [March 21, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/getting-the-module-name-with-objectspace/89596 "2007-03-21T13:58:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 21, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/getting-the-module-name-with-objectspace/89596/1 "2007-03-21T13:58:20Z")

</div>

Hey 🙂

I’m trying to create a method for making a sitemap dynamically. It  
works great for flat sites where you simply have your controllers in  
the app/controllers directory. In this case, I can extract the  
controller names like,

@controllers  
ObjectSpace.subclasses\_of(ActionController::Base).each do |obj|  
@controllers["#{obj.controller\_name}"] = obj  
end

However, now I’ve divided the site into modules, that is, I have for  
instance both Store::ItemsController and Manage::ItemsController,  
which reside in app/controllers/store and app/controllers/manage  
respectively.

This causes my code above to basically (as it seems) discard the  
“duplicate” controllers when traversing the classes. What I’d like to  
do is mimic the hierarchy in my module::controller::action structure,  
but I don’t know how to do that…

I’d like to have a three dimensional array like, [module\_name]  
[controller\_name][action\_name]

Help?

Thanks 🙂

Daniel
