# Get all classes which include a module

**URL:** <https://www.ruby-forum.com/t/get-all-classes-which-include-a-module/106455>\
**Category:** Rails\
**Created:** [June 10, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/get-all-classes-which-include-a-module/106455 "2007-06-10T19:30:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [June 10, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/get-all-classes-which-include-a-module/106455/1 "2007-06-10T19:30:47Z")

</div>

Hey,

while building a small CMS I now have the problem to create some  
content elements. To be able to make a selectbox (or something  
similar), I have to figure out, which content elements (each has its  
own model-class) exist.  
My plan was to extend the model-classes with some kind of module to  
add some common methods and use  
self.included(class) in the module to get all classes which include  
this module. But the problem is, that this method is only called when  
an instance of the class is created.  
So the question is, how do I fetch all classes? Is there a common way  
to do this and/or do I have to iterate over the files and read this  
out (and how is this done 🙂 )?

Thanks

Mike

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [June 11, 2007, 1:34am UTC](https://www.ruby-forum.com/t/get-all-classes-which-include-a-module/106455/2 "2007-06-11T01:34:29Z")

</div>

Maybe to give it a more general touch and clearify things a little:

The problem is, that I need some kind of configuration and I have to  
know, what kind of content elements exist in the application.  
One approach would be to have a configuration-file (yaml) or db-table  
and say there something like: content\_elements = text, image…  
The problem would be, that if I want to add another type of element, I  
have to edit this file or the db field.  
Instead I want to have the opportunity to create a list of all content  
elements at runtime and so make it possible to add different types of  
content elements by only saying “acts\_as\_content\_element” (for eg.) in  
a model class. The problem is, that I have to find a way to know the  
models, which are content elements.

Anybody came over this problem yet? Would this be a good approach and  
how can I do this? Or is the usage of some kind of configuration-file  
the better way?

I think in the future developement of this project I’m going to hit  
this problem again, when it comes to the creation of a menu based on a  
few specific controllers, so the solution has to fit here as well.

Maybe someone as a general (or the better a more detailed) solution?!?

Mike
