# How to structure ruby libraries?

**URL:** <https://www.ruby-forum.com/t/how-to-structure-ruby-libraries/98094>\
**Category:** Ruby\
**Created:** [July 12, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/how-to-structure-ruby-libraries/98094 "2006-07-12T15:42:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/how-to-structure-ruby-libraries/98094/1 "2006-07-12T15:42:46Z")

</div>

hello

we are building a new ruby library which will probably consist of  
several  
dozens of source files.  
we want to package it in a gem.

are there any conventions on how to structure the directories of the  
library ?  
in some libs I found something like this

ls -l mylib-1.0.0.0  
doc  
examples  
lib  
pkg  
Rakefile  
README  
test

Rakefile and README would be files, the rest directories.  
Rakefile would be use for building the gem.

the lib directory would look like this:  
ls -l lib  
mylib.rb  
mylib

and within mylib there would be all the source code

are there any conventions on how to do this ?

Markus

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2006, 3:52pm UTC](https://www.ruby-forum.com/t/how-to-structure-ruby-libraries/98094/2 "2006-07-12T15:52:50Z")

</div>

removed\_email\_address@domain.invalid wrote:

> ls -l mylib-1.0.0.0
> 
> the lib directory would look like this:  
> ls -l lib  
> mylib.rb  
> mylib
> 
> and within mylib there would be all the source code
> 
> are there any conventions on how to do this ?

[http://i.loveruby.net/en/projects/setup/doc/devel.html](http://i.loveruby.net/en/projects/setup/doc/devel.html)

T.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2006, 9:43pm UTC](https://www.ruby-forum.com/t/how-to-structure-ruby-libraries/98094/3 "2006-07-12T21:43:10Z")

</div>

Hi Markus,

Most of the installed libraries have used (for example)  
/usr/local/lib/ruby/site\_ruby/1.8/:  
mylib.rb  
mylib/

as you have shown.

Some of the more recent additions install just the single directory  
/usr/local/lib/ruby/site\_ruby/1.8/svg/:  
svg.rb  
{other files}

This last is from rubysvg-1.0.3 package.  
An application that uses that library has this require:

require “svg/svg”

I prefer the latter, as this tends to keep all installed files under  
one  
directory, (the difference over the former is a small preference)

Best Regards,  
Gerald
