Reputation: 9329
There are many questions and answers regarding checking the Ruby Gem path from the command line. However I haven't been able to work out how to check it from within a Ruby script. I need to do so because I have a require
which works fine from irb, but fails within my script with a "cannot load such file" error.
How can I check where Ruby is searching for Gems from WITHIN the script?
EDIT:
The fix for my require
turned out to be to add the required gem to the gemspec file as a dependency. However that doesn't explain why irb was okay but the script wasn't...since the dependency was available, shouldn't they both have found it?
Upvotes: 0
Views: 459
Reputation: 6223
I think you're looking for $LOAD_PATH
. Being a list, you can append new search paths to it using push
or unshift
. Also, if you're using a Gemfile for your script, you can try to execute your script using this command bundle exec ruby my_script.rb
.
Upvotes: 3