# Organizing Ruby code

**URL:** <https://www.ruby-forum.com/t/organizing-ruby-code/58192>\
**Category:** Ruby\
**Created:** [April 19, 2006, 3:45pm UTC](https://www.ruby-forum.com/t/organizing-ruby-code/58192 "2006-04-19T15:45:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![donv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@donv](https://www.ruby-forum.com/u/donv)\
**Post date:** [April 19, 2006, 3:45pm UTC](https://www.ruby-forum.com/t/organizing-ruby-code/58192/1 "2006-04-19T15:45:20Z")

</div>

Hi all!

I have now completed two web projects using Ruby On Rails in The Real  
World and I am very happy about it. Woohoo to me!

In RoR all the components have been assigned a location in the project  
tree and I find this very helpful.

I am looking for conventions for how to organize business logic that  
does not fit easily into the model-view-controller categories.

I guess this is code that goes into the “lib” directory, and it should  
be organized like any Ruby code. The problem is, I have not found any  
conventions for how to organize regular Ruby code.

In Java I am forced to have one class per file, the file must be called  
the same as the class, and the file should be placed in a directory with  
the same name as the package of the class. These limitations are of  
enormous help since it makes finding everything very easy.

Is there something similar for Ruby code? Should I use modules where I  
use packages in Java? Is there a relationship between module names and  
file location? How many classes per file? How many modules per file?

Any tips on how to organize Ruby code is appreciated. I am looking for  
a common convention, so that if I follow it, the next Ruby programmer  
that comes into the project immediately knows where to find all the  
components.

Recommendations for books and websites are always welcome, and so are  
any other good sources for information. On the Ruby/Rails topic I have  
read the Pickaxe book, Ruby in a Nutshell, and Agile Programming In Ruby  
On Rails.

Any comments on this are appreciated.

Uwe K.

---

<div class="post-metadata">

**Author:** ![donv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@donv](https://www.ruby-forum.com/u/donv)\
**Post date:** [April 19, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/organizing-ruby-code/58192/2 "2006-04-19T17:45:54Z")

</div>

Uwe K. wrote:

I’d recomend looking through the source of other well known projects,  
this was what I’ve done for the most part. One specific place I’d  
recomend looking is in the Rake source code, Rails is another good one.

---

<div class="post-metadata">

**Author:** ![donv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@donv](https://www.ruby-forum.com/u/donv)\
**Post date:** [April 26, 2006, 12:17am UTC](https://www.ruby-forum.com/t/organizing-ruby-code/58192/3 "2006-04-26T00:17:46Z")

</div>

> I’d recomend looking through the source of other well known projects,  
> this was what I’ve done for the most part. One specific place I’d  
> recomend looking is in the Rake source code, Rails is another good one.

Hopefully, someone will be nice enough to publish a little  
canonical tree when they are done with their investigation.

Craig McClanahan did one for web apps written in Java  
that was very helpful. (It was at the Apache site once  
upon a time, but I couldn’t find it the last time I looked.)

P.S.  
Thanks to Stephen M. for his writeup. Very useful.
