How to add your own scripts to Ruby loader path and solve load errors

These days I started to play with Ruby and I needed to figure out how to load my own scripts from a sub-directory into my project folder.

I needed to do it because Ruby 1.9.3 does not include the current directory in its default loader path and if one issues a require or load command to a file that is not in the current Ruby loader path he/she will get the an error message like no such file to load.

My project structure is as follow:

Picture 1 – Project structure

After some research in the net I found out a couple of methods. The one I liked more is the following:

Listing 1 – adding your own folders to Ruby loader PATH

You just have to add it into your main script (the one that will load the others) prior to require command. So, my main ruby file became something like this:

Listing 2  – main.rb excerpt.

Enjoy.

Please, try my games, play free on-line games on my site, tweet this post url and share it on facebook, google+ and other social medias.

Share in top social networks!
This entry was posted in development and tagged , , . Bookmark the permalink.