Normally when you run an executable from a gem Rubygems will set up the LOAD_PATH
for you so that it contains your gems’ lib directory. Obviously when you run the script in development Rubygems doesn’t get the chance to set things up for you so you will need to do it yourself.
One way to do this is in the script file itself. For example the Haml and Redcarpet gems do this. Somewhere near the top of your executable you would have something like this:
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
(assuming a fairly typical directory layout).
Another way, if you want to avoid manipulating the load path in code, would be to add the lib dir in the command line. The -I
option to the ruby
command lets you do this, so you could run:
$ ruby -Ilib/ bin/roar
from the top level of your gem.
Alternatively you could use the RUBYLIB
environment variable:
$ RUBYLIB=lib ruby bin/roar
or even (if bin/roar
has a shebang line and is executable):
$ RUBYLIB=lib ./bin/roar
You could even export RUBYLIB
so you didn’t need to specify it each time, but you would need to be careful about leaving it set if you did that.