# How to organize modules

**URL:** <https://www.ruby-forum.com/t/how-to-organize-modules/147899>\
**Category:** Rails\
**Created:** [September 6, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/how-to-organize-modules/147899 "2008-09-06T19:33:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Kireev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ee59a6/32.png) [@Alexander\_Kireev](https://www.ruby-forum.com/u/Alexander_Kireev)\
**Post date:** [September 6, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/how-to-organize-modules/147899/1 "2008-09-06T19:33:42Z")

</div>

Hi!  
I have rails application. Now I want add there some modules. I try to  
do it using plugins and have a problem. Maybe I doing something wrong.

I build module as a class. Each module has own class definition with  
necessary functionality. Now I want to access them (get list of  
modules for example). How should I access them?

I tried to declare a registry class in /lib and build a list of  
modules them (list is filled in init.rb of each module). Then I create  
a page where list of modules would be shown.

And now I have a problem.  
In first access page displays everything ok. But next access displays  
an empty page!

My “module registry” looks like

private\_class\_method :new

def self.instance  
@mod = new unless @mod  
@mod  
end

def register\_module (mod)  
@modules = [] if !@modules  
@modules \<\< mod  
end

def modules  
@modules = [] if !@modules  
@modules  
end

What am I doing wrong? Do you have links to articles about  
organization architecture like this?
