# Typical Ruby (non-rails) project structure

**URL:** <https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306>\
**Category:** ruby-talk\
**Created:** [22 July 2010 17:41 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306 "2010-07-22T17:41:57Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Carl\_Jenkins](https://rubytalk.org/u/Carl_Jenkins)\
**Post date:** [22 July 2010 17:41 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/1 "2010-07-22T17:41:57Z")

</div>

What is/are the best-practice(s) for a Ruby project structure?

As I am just learning Ruby I put everything in one file but, now I am  
learning about Modules etc..

In Java, classes where in packages which helped with code organization.  
Is there a typical way to layout a Ruby project structure?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Marvin\_GA\_lker](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Marvin\_GA\_lker](https://rubytalk.org/u/Marvin_GA_lker)\
**Post date:** [22 July 2010 18:08 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/2 "2010-07-22T18:08:03Z")

</div>

Carl Jenkins wrote:

> What is/are the best-practice(s) for a Ruby project structure?
> 
> As I am just learning Ruby I put everything in one file but, now I am  
> learning about Modules etc..
> 
> In Java, classes where in packages which helped with code organization.  
> Is there a typical way to layout a Ruby project structure?

I think the RubyGems guidelines describe how a ruby project is typically  
structured. Additionally, I tend to create a directory for each module  
and a file for each class:

/  
&nbsp;&nbsp;bin/ #Put your executables here  
&nbsp;&nbsp;data/ #Everything else needed for the project  
&nbsp;&nbsp;doc/ #RDoc for the lib/ directory  
&nbsp;&nbsp;ext/ #C-Extensions go here  
&nbsp;&nbsp;lib/ #Everything internal is handled here  
&nbsp;&nbsp;&nbsp;&nbsp;- my\_namespace.rb #Contains module methods for MyNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;my\_namespace/ #Directory for classes in MyNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_class.rb #Contains MyClass  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_inner\_namespace/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_2nd\_class.rb

Marvin

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Tim\_Pease](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@Tim\_Pease](https://rubytalk.org/u/Tim_Pease)\
**Post date:** [22 July 2010 18:41 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/3 "2010-07-22T18:41:08Z")

</div>

Take a look at Mr Bones. It encapsulates many ruby best-practices and lots of rake tasks to take care of the day-to-day development tasks

gem install bones

bones create new\_project  
cd new\_project

rake -T # shows you all the available tasks  
rake bones:help # shows you the various project configuration settings

Other tools in the same vein as Mr Bones are "hoe" and "jeweler"

gem install hoe  
gem install jeweler

I'm slightly partial to Mr Bones being the author and all.

Blessings,  
TwP

> **···**
>
> On Jul 22, 2010, at 11:41 AM, Carl Jenkins wrote:
> 
> > What is/are the best-practice(s) for a Ruby project structure?
> > 
> > As I am just learning Ruby I put everything in one file but, now I am  
> > learning about Modules etc..
> > 
> > In Java, classes where in packages which helped with code organization.  
> > Is there a typical way to layout a Ruby project structure?

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [22 July 2010 20:50 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/4 "2010-07-22T20:50:07Z")

</div>

[http://wiki.github.com/proutils/setup/creating-packages](http://wiki.github.com/proutils/setup/creating-packages)

> **···**
>
> On Jul 22, 1:41 pm, Carl Jenkins \<carljenk...@gmail.com\> wrote:
> 
> > What is/are the best-practice(s) for a Ruby project structure?
> > 
> > As I am just learning Ruby I put everything in one file but, now I am  
> > learning about Modules etc..
> > 
> > In Java, classes where in packages which helped with code organization.  
> > Is there a typical way to layout a Ruby project structure?

---

<div class="post-metadata">

**Author:** ![Mark\_T](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mark\_T](https://rubytalk.org/u/Mark_T)\
**Post date:** [23 July 2010 01:11 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/5 "2010-07-23T01:11:35Z")

</div>

My advice is to build a unique folder at root on a unix boxen (ex: RP1).  
In your profile, modify RUBYLIB to point to a sub folder of this.  
In your profile, modify GEM\_HOME to point to an adjacent folder to this.

Modify Then install Ruby to said folder with .configure option.  
Install gems.  
In your profile: RUBYOPT=rubygems,

Then all updates to Ruby or gems will only require user perms.  
Your code can be in a subfolder of (RP1).  
Additionally, the entire folder structure can be easily backed up,  
transferred or rsync'd.  
Handy for remote instance installs.  
Use VMware/Virtualbox as local test area.

Then get funky with code paths.

MarkT

---

<div class="post-metadata">

**Author:** ![R\_Kumar](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@R\_Kumar](https://rubytalk.org/u/R_Kumar)\
**Post date:** [23 July 2010 06:26 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/6 "2010-07-23T06:26:50Z")

</div>

Carl Jenkins wrote:

> What is/are the best-practice(s) for a Ruby project structure?
> 
> As I am just learning Ruby I put everything in one file but, now I am  
> learning about Modules etc..
> 
> In Java, classes where in packages which helped with code organization.  
> Is there a typical way to layout a Ruby project structure?

I would suggest using the same structure as the gem structure. You can  
use jeweler or any of the others mentioned. THis is especially useful if  
you might want to release as a gem later. In any case, if you do release  
gems in addition to this, its best to be used to one structure.

If you are creating command-line programs or scripts, do look at thor,  
commander and gli. And hibernate.

It's up to you to put one or more classes in one file.

Typically, we have multiple folders within "lib", so these folders can  
be your packages. There was a thread recently on modules, it has some  
good links for more info.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Richard\_Conroy1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Richard\_Conroy1](https://rubytalk.org/u/Richard_Conroy1)\
**Post date:** [23 July 2010 18:13 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/7 "2010-07-23T18:13:07Z")

</div>

> What is/are the best-practice(s) for a Ruby project structure?

Use the gem structure. Its pretty universal for packaging, structuring and  
even deploying Ruby projects. Rails projects use their own structure, but  
its well documented too.

> As I am just learning Ruby I put everything in one file but, now I am  
> learning about Modules etc..
> 
> In Java, classes where in packages which helped with code organization.  
> Is there a typical way to layout a Ruby project structure?

Note that in Java packages also map 1:1 with the directory structure of the  
classes, that is quite strict. In Ruby, the hierarchy of namespaces has  
no implications on how ruby files are loaded.

I haven't seen much information, beyond the replies here, that implies  
any consensus on how these files are structured or named.

It is worth researching exactly how 'require' and the load path works in  
Ruby. It is a bit alien coming from a Java background, but the mechanics  
of how it works will imply its own best practices.

> **···**
>
> On Thu, Jul 22, 2010 at 6:41 PM, Carl Jenkins \<carljenkins@gmail.com\> wrote:
> 
> --
> 
> > **[Richard Conroy's Personal Blog](http://richardconroy.blogspot.com)**
> >
> > Random thoughts on Life, Pictures, Sailing, Software Development, Games, Skiing and random things from the internet. May contain Rants.

---

<div class="post-metadata">

**Author:** ![Carl\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Carl\_Jenkins](https://rubytalk.org/u/Carl_Jenkins)\
**Post date:** [22 July 2010 18:12 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/8 "2010-07-22T18:12:47Z")

</div>

> /  
> &nbsp;&nbsp;bin/ #Put your executables here  
> &nbsp;&nbsp;data/ #Everything else needed for the project  
> &nbsp;&nbsp;doc/ #RDoc for the lib/ directory  
> &nbsp;&nbsp;ext/ #C-Extensions go here  
> &nbsp;&nbsp;lib/ #Everything internal is handled here  
> &nbsp;&nbsp;&nbsp;&nbsp;- my\_namespace.rb #Contains module methods for MyNamespace  
> &nbsp;&nbsp;&nbsp;&nbsp;my\_namespace/ #Directory for classes in MyNamespace  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_class.rb #Contains MyClass  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_inner\_namespace/  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_2nd\_class.rb
> 
> Marvin

So all my code looks like it would go under lib/ correct?  
What does -my\_namespace.rb refer to? Is this the Ruby class driver for  
the applicaiton? Also my\_inner\_namespace.. not sure I understand this?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Marvin\_GA\_lker](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Marvin\_GA\_lker](https://rubytalk.org/u/Marvin_GA_lker)\
**Post date:** [22 July 2010 19:37 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/9 "2010-07-22T19:37:44Z")

</div>

Tim Pease wrote:

> **···**
>
> > On Jul 22, 2010, at 11:41 AM, Carl Jenkins wrote:
> > 
> > > What is/are the best-practice(s) for a Ruby project structure?
> > > 
> > > As I am just learning Ruby I put everything in one file but, now I am  
> > > learning about Modules etc..
> > > 
> > > In Java, classes where in packages which helped with code organization.  
> > > Is there a typical way to layout a Ruby project structure?
> > 
> > Take a look at Mr Bones. It encapsulates many ruby best-practices and  
> > lots of rake tasks to take care of the day-to-day development tasks
> > 
> > gem install bones
> > 
> > bones create new\_project  
> > cd new\_project
> > 
> > rake -T # shows you all the available tasks  
> > rake bones:help # shows you the various project configuration  
> > settings
> > 
> > Other tools in the same vein as Mr Bones are "hoe" and "jeweler"
> > 
> > gem install hoe  
> > gem install jeweler
> > 
> > I'm slightly partial to Mr Bones being the author and all.
> > 
> > Blessings,  
> > TwP
> 
> I'm not sure that's what the OP wants. He didn't state he wanted to  
> build gems, he just wanted to know how a general Ruby projekt is  
> structured (an end-user desktop app maybe?). Well, if one consideres a  
> gem as the standard way to write a general Ruby project... 😉
> 
> Marvin  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Carl\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Carl\_Jenkins](https://rubytalk.org/u/Carl_Jenkins)\
**Post date:** [23 July 2010 01:27 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/10 "2010-07-23T01:27:22Z")

</div>

Mark T wrote:

> My advice is to build a unique folder at root on a unix boxen (ex: RP1).  
> In your profile, modify RUBYLIB to point to a sub folder of this.  
> In your profile, modify GEM\_HOME to point to an adjacent folder to this.
> 
> Modify Then install Ruby to said folder with .configure option.  
> Install gems.  
> In your profile: RUBYOPT=rubygems,
> 
> Then all updates to Ruby or gems will only require user perms.  
> Your code can be in a subfolder of (RP1).  
> Additionally, the entire folder structure can be easily backed up,  
> transferred or rsync'd.  
> Handy for remote instance installs.  
> Use VMware/Virtualbox as local test area.
> 
> Then get funky with code paths.
> 
> MarkT

I appreciate your advice but, didn't understand most of what you were  
trying to tell me. Still a bit of a greenhorn with Ruby really.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Carl\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Carl\_Jenkins](https://rubytalk.org/u/Carl_Jenkins)\
**Post date:** [23 July 2010 17:54 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/11 "2010-07-23T17:54:22Z")

</div>

Tim Pease wrote:

> **···**
>
> > On Jul 22, 2010, at 11:41 AM, Carl Jenkins wrote:
> > 
> > > What is/are the best-practice(s) for a Ruby project structure?
> > > 
> > > As I am just learning Ruby I put everything in one file but, now I am  
> > > learning about Modules etc..
> > > 
> > > In Java, classes where in packages which helped with code organization.  
> > > Is there a typical way to layout a Ruby project structure?
> > 
> > Take a look at Mr Bones. It encapsulates many ruby best-practices and  
> > lots of rake tasks to take care of the day-to-day development tasks
> > 
> > gem install bones
> > 
> > bones create new\_project  
> > cd new\_project
> > 
> > rake -T # shows you all the available tasks  
> > rake bones:help # shows you the various project configuration  
> > settings
> > 
> > Other tools in the same vein as Mr Bones are "hoe" and "jeweler"
> > 
> > gem install hoe  
> > gem install jeweler
> > 
> > I'm slightly partial to Mr Bones being the author and all.
> > 
> > Blessings,  
> > TwP
> 
> I just tried 'bones' and it works perfectly!
> 
> I did install 'jeweler' but, for some reason I am getting errors;  
> probably because I do not have git installed or an account yet....
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Carl\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Carl\_Jenkins](https://rubytalk.org/u/Carl_Jenkins)\
**Post date:** [23 July 2010 18:28 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/12 "2010-07-23T18:28:17Z")

</div>

Richard Conroy wrote:

> > What is/are the best-practice(s) for a Ruby project structure?
> 
> Use the gem structure. Its pretty universal for packaging, structuring  
> and  
> even deploying Ruby projects. Rails projects use their own structure,  
> but  
> its well documented too.
> 
> > As I am just learning Ruby I put everything in one file but, now I am  
> > learning about Modules etc..
> > 
> > In Java, classes where in packages which helped with code organization.  
> > Is there a typical way to layout a Ruby project structure?
> 
> Note that in Java packages also map 1:1 with the directory structure of  
> the  
> classes, that is quite strict. In Ruby, the hierarchy of namespaces has  
> no implications on how ruby files are loaded.
> 
> I haven't seen much information, beyond the replies here, that implies  
> any consensus on how these files are structured or named.
> 
> It is worth researching exactly how 'require' and the load path works in  
> Ruby. It is a bit alien coming from a Java background, but the mechanics  
> of how it works will imply its own best practices.

When using them gem structure for example I have something like this.

new\_proj/  
bin/  
lib/  
&nbsp;&nbsp;&nbsp;&nbsp;common/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-new\_file.rb  
spec/  
test/  
&nbsp;&nbsp;-new\_test.rb

In order to test the new\_file.rb my new\_test.rb must have the path to  
the new\_file.rb as the require correct? Something like require  
'../lib/common/new\_file'

Or is there a different way to do that?

Thanks for all the help - (everyone) this is most helpful!

> **···**
>
> > On Thu, Jul 22, 2010 at 6:41 PM, Carl Jenkins \<carljenkins@gmail.com\> \> wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Marvin\_GA\_lker](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Marvin\_GA\_lker](https://rubytalk.org/u/Marvin_GA_lker)\
**Post date:** [22 July 2010 18:33 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/13 "2010-07-22T18:33:11Z")

</div>

Carl Jenkins wrote:

> > /  
> > &nbsp;&nbsp;bin/ #Put your executables here  
> > &nbsp;&nbsp;data/ #Everything else needed for the project  
> > &nbsp;&nbsp;doc/ #RDoc for the lib/ directory  
> > &nbsp;&nbsp;ext/ #C-Extensions go here  
> > &nbsp;&nbsp;lib/ #Everything internal is handled here  
> > &nbsp;&nbsp;&nbsp;&nbsp;- my\_namespace.rb #Contains module methods for MyNamespace  
> > &nbsp;&nbsp;&nbsp;&nbsp;my\_namespace/ #Directory for classes in MyNamespace  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_class.rb #Contains MyClass  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_inner\_namespace/  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_2nd\_class.rb
> > 
> > Marvin
> 
> So all my code looks like it would go under lib/ correct?  
> What does -my\_namespace.rb refer to? Is this the Ruby class driver for  
> the applicaiton? Also my\_inner\_namespace.. not sure I understand this?

Most of the code goes under lib/, that's correct. The -my\_namespace.rb  
isn't anything special, my\_namespace.rb is a regular Ruby file. I just  
used a - sign to distinguish a file from a directory, i.e. if I write

dir/  
&nbsp;&nbsp;- file1.rb  
&nbsp;&nbsp;- file2.rb  
&nbsp;&nbsp;subdir/  
&nbsp;&nbsp;&nbsp;&nbsp;- file3.rb

then those ending with / are directories and those beginning with - are  
files. Regarding your other question I just repost my example with more  
comments:

/  
&nbsp;&nbsp;bin/ #Put your executables here  
&nbsp;&nbsp;data/ #Everything else needed for the project, e.g. graphics  
&nbsp;&nbsp;doc/ #RDoc for the lib/ directory, auto-generated by running the rdoc  
command  
&nbsp;&nbsp;ext/ #C-Extensions go here  
&nbsp;&nbsp;lib/ #Everything internal is handled here  
&nbsp;&nbsp;&nbsp;&nbsp;- my\_namespace.rb #Contains module methods for MyNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;my\_namespace/ #Directory for classes in MyNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_class.rb #Contains MyNamespace::MyClass  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_inner\_namespace/ #Directry for classes in  
MyNamespace::MyInnerNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_2nd\_class.rb #Contains  
MyNamespace::MyInnerNamespace::My2ndClass

Marvin

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Brabuhr](https://avatars.discourse-cdn.com/v4/letter/b/919ad9/32.png) [@Brabuhr](https://rubytalk.org/u/Brabuhr)\
**Post date:** [22 July 2010 18:38 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/14 "2010-07-22T18:38:06Z")

</div>

> > /  
> > bin/ #Put your executables here  
> > data/ #Everything else needed for the project  
> > doc/ #RDoc for the lib/ directory  
> > ext/ #C-Extensions go here  
> > lib/ #Everything internal is handled here  
> > - my\_namespace.rb #Contains module methods for MyNamespace  
> > my\_namespace/ #Directory for classes in MyNamespace  
> > - my\_class.rb #Contains MyClass  
> > my\_inner\_namespace/  
> > - my\_2nd\_class.rb
> 
> So all my code looks like it would go under lib/ correct?  
> What does -my\_namespace.rb refer to? Is this the Ruby class driver for  
> the applicaiton? Also my\_inner\_namespace.. not sure I understand this?

I think he means something like:

/  
&nbsp;&nbsp;&nbsp;&nbsp;lib/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;library\_name.rb  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# This is the file that consumers of this  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# library will require; it will create the  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# module and load the actual library.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require './library\_name/library\_class'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module LibraryName  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VERSION = "..."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;library\_name/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;library\_class.rb  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# The class that implements the library.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module LibraryName  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class LibraryClass  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;another\_class.rb  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# A support class for the library.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module LibraryName  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class AnotherClass  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;submodule/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;yet\_another\_class.rb  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# A support class in a submodule.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module LibraryName  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module Submodule  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class YetAnotherClass  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

---

<div class="post-metadata">

**Author:** ![Brabuhr](https://avatars.discourse-cdn.com/v4/letter/b/919ad9/32.png) [@Brabuhr](https://rubytalk.org/u/Brabuhr)\
**Post date:** [23 July 2010 21:04 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/15 "2010-07-23T21:04:49Z")

</div>

Just looked at one of my bones-generated projects:

$ cat spec/spec\_helper.rb

require File.expand\_path(  
&nbsp;&nbsp;&nbsp;&nbsp;File.join(File.dirname(\_\_FILE\_\_), %w[.. lib fooz]))  
[...]

> **···**
>
> On Fri, Jul 23, 2010 at 2:28 PM, Carl Jenkins \<carljenkins@gmail.com\> wrote:
> 
> > Richard Conroy wrote:
> > 
> > > On Thu, Jul 22, 2010 at 6:41 PM, Carl Jenkins \<carljenkins@gmail.com\> \>\> wrote:
> > > 
> > > > What is/are the best-practice(s) for a Ruby project structure?
> > > 
> > > Use the gem structure. Its pretty universal for packaging, structuring  
> > > and  
> > > even deploying Ruby projects. Rails projects use their own structure,  
> > > but  
> > > its well documented too.
> > 
> > When using them gem structure for example I have something like this.
> > 
> > new\_proj/  
> > bin/  
> > lib/  
> > common/  
> > -new\_file.rb  
> > spec/  
> > test/  
> > -new\_test.rb
> > 
> > In order to test the new\_file.rb my new\_test.rb must have the path to  
> > the new\_file.rb as the require correct? Something like require  
> > '../lib/common/new\_file'
> > 
> > Or is there a different way to do that?

---

<div class="post-metadata">

**Author:** ![Jarmo\_Pertman](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@Jarmo\_Pertman](https://rubytalk.org/u/Jarmo_Pertman)\
**Post date:** [27 July 2010 16:47 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/16 "2010-07-27T16:47:08Z")

</div>

I would play with the $LOAD\_PATH in your spec\_helper or whatnot:

# spec\_helper.rb  
$LOAD\_PATH.unshift(File.join(File.dirname(\_\_FILE\_\_), "../lib"))

# blah\_spec.rb  
require "spec\_helper" # require in every spec file  
require "my\_class" # now it's possible to require my\_class from lib  
dir because of changed $LOAD\_PATH

describe MyClass do  
&nbsp;&nbsp;it "test, test, test!" do  
&nbsp;&nbsp;&nbsp;&nbsp;MyClass.new.should be  
&nbsp;&nbsp;end  
end

Or, if using really RSpec, then create a spec.opts file into the spec  
directory and require it from there:  
--require  
spec\_helper

Then you can remove those require statements from spec files  
themselves. Although if you're using some kind of an IDE, then they  
might get confused, but i don't mind 🙂

> **···**
>
> On Jul 23, 9:28 pm, Carl Jenkins \<carljenk...@gmail.com\> wrote:
> 
> > In order to test the new\_file.rb my new\_test.rb must have the path to  
> > the new\_file.rb as the require correct? Something like require  
> > '../lib/common/new\_file'
> > 
> > Or is there a different way to do that?
> > 
> > Thanks for all the help - (everyone) this is most helpful!
> 
> -----  
> Jarmo Pertman  
> IT does really matter - [http://www.itreallymatters.net](http://www.itreallymatters.net)

---

<div class="post-metadata">

**Author:** ![Marvin\_GA\_lker](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Marvin\_GA\_lker](https://rubytalk.org/u/Marvin_GA_lker)\
**Post date:** [22 July 2010 18:36 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/17 "2010-07-22T18:36:31Z")

</div>

Marvin Gülker wrote:

> /  
> &nbsp;&nbsp;bin/ #Put your executables here  
> &nbsp;&nbsp;data/ #Everything else needed for the project, e.g. graphics  
> &nbsp;&nbsp;doc/ #RDoc for the lib/ directory, auto-generated by running the rdoc  
> command  
> &nbsp;&nbsp;ext/ #C-Extensions go here  
> &nbsp;&nbsp;lib/ #Everything internal is handled here  
> &nbsp;&nbsp;&nbsp;&nbsp;- my\_namespace.rb #Contains module methods for MyNamespace  
> &nbsp;&nbsp;&nbsp;&nbsp;my\_namespace/ #Directory for classes in MyNamespace  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_class.rb #Contains MyNamespace::MyClass  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_inner\_namespace/ #Directry for classes in  
> MyNamespace::MyInnerNamespace  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_2nd\_class.rb #Contains  
> MyNamespace::MyInnerNamespace::My2ndClass

Oops, that got malformatted. Here's a better version:

/  
&nbsp;&nbsp;bin/ #Put your executables here  
&nbsp;&nbsp;data/ #Everything else needed for the project, e.g. graphics  
&nbsp;&nbsp;doc/ #RDoc for the lib/ dir, auto-generated by running "rdoc"  
&nbsp;&nbsp;ext/ #C-Extensions go here  
&nbsp;&nbsp;lib/ #Everything internal is handled here  
&nbsp;&nbsp;&nbsp;&nbsp;- my\_namespace.rb #Contains module methods for MyNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;my\_namespace/ #Directory for classes in MyNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_class.rb #Contains MyNamespace::MyClass  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_inner\_namespace/ #classes in MyNamespace::MyInnerNamespace  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- my\_2nd\_class.rb #MyNamespace::MyInnerNamespace::My2ndClass

Marvin

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Carl\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Carl\_Jenkins](https://rubytalk.org/u/Carl_Jenkins)\
**Post date:** [23 July 2010 21:58 UTC](https://rubytalk.org/t/typical-ruby-non-rails-project-structure/59306/18 "2010-07-23T21:58:08Z")

</div>

unknown wrote:

> **···**
>
> > On Fri, Jul 23, 2010 at 2:28 PM, Carl Jenkins \<carljenkins@gmail.com\> \> wrote:
> > 
> > > > but
> > > 
> > > �test/  
> > > �-new\_test.rb
> > > 
> > > In order to test the new\_file.rb my new\_test.rb must have the path to  
> > > the new\_file.rb as the require correct? Something like require  
> > > '../lib/common/new\_file'
> > > 
> > > Or is there a different way to do that?
> > 
> > Just looked at one of my bones-generated projects:
> > 
> > $ cat spec/spec\_helper.rb
> > 
> > require File.expand\_path(  
> > &nbsp;&nbsp;&nbsp;&nbsp;File.join(File.dirname(\_\_FILE\_\_), %w[.. lib fooz]))  
> > [...]
> 
> haha - that's genius..
> 
> (I should have known better and just looked myself.)
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
