# How can I organize my project in the best way?

**URL:** <https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460>\
**Category:** Ruby\
**Created:** [April 22, 2008, 12:46pm UTC](https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460 "2008-04-22T12:46:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christoffer\_LernSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Christoffer\_LernSSS](https://www.ruby-forum.com/u/Christoffer_LernSSS)\
**Post date:** [April 22, 2008, 12:46pm UTC](https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460/1 "2008-04-22T12:46:26Z")

</div>

I’m writing a server for a networked game using ruby, but I keep  
running into issues when organizing them.

Basically I have a structure looking a bit like this:

lib/  
testclient/  
gamemodel/  
gamecommands/  
server/  
utils/  
test/  
gamemodel/  
gamecommands/  
server/  
utils/

The problem is the paths for the requires.

For a test in say test/gamemodel, I need to require something  
like …/…/lib/gamemodel/  
But when running the same test from some test\_all.rb in /test, the  
correct require is of course …/lib/gamemodel/  
(The natural way would have been to simply write require )

It is possible to fix this problem by appending to the load path, but  
this means rows of duplicate code in every test file.

The problem naturally extends to the lib where you also have to decide  
where the code supposedly is run from.

Any suggestions on neat ways of solving this problem or are there  
perhaps packages available to make this work automatically?

/Christoffer

---

<div class="post-metadata">

**Author:** ![Christoffer\_LernSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Christoffer\_LernSSS](https://www.ruby-forum.com/u/Christoffer_LernSSS)\
**Post date:** [April 22, 2008, 1:11pm UTC](https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460/2 "2008-04-22T13:11:17Z")

</div>

On Apr 22, 6:45 am, Christoffer Lernö [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> utils/
> 
> ```
> 
> But when running the same test from some test\_all.rb in /test, the  
> perhaps packages available to make this work automatically?
> 
> /Christoffer

Hi Christoffer,

When testing your lib you should only need to add lib/ to the load  
path once. For instance you might do:

ruby -Ilib test/sometest.rb

T.

---

<div class="post-metadata">

**Author:** ![Christoffer\_LernSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Christoffer\_LernSSS](https://www.ruby-forum.com/u/Christoffer_LernSSS)\
**Post date:** [April 22, 2008, 1:56pm UTC](https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460/3 "2008-04-22T13:56:41Z")

</div>

> Hi Christoffer,
> 
> When testing your lib you should only need to add lib/ to the load  
> path once. For instance you might do:
> 
> ruby -Ilib test/sometest.rb

Yes, but if the test is in

test/client/tc\_connect.rb

then I might need to require

test/test\_common.rb  
lib/client/connect.rb

Again I need to add these libs differently depending on where I start  
my test.

/Christoffer

---

<div class="post-metadata">

**Author:** ![Christoffer\_LernSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Christoffer\_LernSSS](https://www.ruby-forum.com/u/Christoffer_LernSSS)\
**Post date:** [April 22, 2008, 2:47pm UTC](https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460/4 "2008-04-22T14:47:04Z")

</div>

On Apr 22, 7:55 am, Christoffer Lernö [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> then I might need to require
> 
> test/test\_common.rb

You can add test/ to the load path as well if you need too.

> lib/client/connect.rb

This should always be:

require ‘client/connect’

> Again I need to add these libs differently depending on where I start  
> my test.

Easiest is to always start from your projects root. Using Rake, for  
instance, makes that automatic. But as an example of manually running  
a test from within the test location:

$ cd test/client  
$ ruby -I…/…/lib;…/…/test tc\_connect.rb

T.

---

<div class="post-metadata">

**Author:** ![Christoffer\_LernSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Christoffer\_LernSSS](https://www.ruby-forum.com/u/Christoffer_LernSSS)\
**Post date:** [April 23, 2008, 7:03am UTC](https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460/5 "2008-04-23T07:03:41Z")

</div>

On 22 Apr 2008, at 14:46, Trans wrote:

> > test/client/tc\_connect.rb
> > 
> > then I might need to require
> > 
> > test/test\_common.rb
> 
> You can add test/ to the load path as well if you need too.

So what you’re saying is basically to add everything to the load path  
and then run with that?

/Christoffer

---

<div class="post-metadata">

**Author:** ![Christoffer\_LernSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Christoffer\_LernSSS](https://www.ruby-forum.com/u/Christoffer_LernSSS)\
**Post date:** [April 25, 2008, 4:48am UTC](https://www.ruby-forum.com/t/how-can-i-organize-my-project-in-the-best-way/135460/6 "2008-04-25T04:48:22Z")

</div>

check out the “need” gem! makes these things simple.

On Apr 22, 2008, at 6:45 AM, Christoffer Lernö wrote:

> utils/  
> like …/…/lib/gamemodel/  
> Any suggestions on neat ways of solving this problem or are there  
> perhaps packages available to make this work automatically?
> 
> /Christoffer

~ Ira Rizdal

Go hang a salami, I’m a lasagna hog
