Path to Ruby Scripts

Ever wondered how to set the path to some Ruby scripts you have written, so you can use them using “require”? There is a very basic solution for this problem. You need to define a system variable called RUBYLIB and point it to the directory containing your Ruby scripts. Then in your script where you want to use the library or script you created, you can simply do a “require” with the name of the script.

e.g. Supposed you created a script chart.rb in /home/foo/ruby/mylib direcory. Now, you want to use this in the app.rb located in /home/foo/ruby/scripts. Here is how you can make it work in a Linux bash environment. You could very well do this in other environments as well with minimal modifications.
In your ~/.bash_profile

export RUBYLIB=$RUBYLIB:/home/foo/ruby/mylib

and then in the app.rb script:

require 'chart'

That’s it.

Share and Enjoy:
  • Digg
  • del.icio.us
  • description
  • Technorati
  • Reddit
  • Facebook
  • blogmarks
  • YahooMyWeb
  • Ma.gnolia

1 Comment »

  1. Jaba said,

    January 10, 2008 @ 7:10 am

    Brilliant, I am very glad I found this, had a bug that I couldn’t find a fix for, but managed to bodge it with this new knowledge. Thanks!

RSS feed for comments on this post · TrackBack URI

Leave a Comment