Put this in the standard library directory (somewhere already in the default download path $: :
# push-loadpath.rb if caller.first $: << File.expand_path(File.dirname(caller.first)) end
Then it should work
% ls /path/to/ bin.rb lib1.rb lib2.rb
caller gives you access to the current call table and tells you which file and where, therefore push-loadpath.rb uses this to add a file that push-loadpath.rb this to the download path.
Note that you must load file, not require it, so that the body can be called several times (once for each time you want to change the download path).
Alternatively, you can wrap the body with a method,
This will allow you to require it and use it as follows:
% ls /path/to/ bin.rb lib1.rb lib2.rb
rampion Apr 25 '09 at 13:56 2009-04-25 13:56
source share