From: Tim Hunter Date: 2007-03-03T05:50:03+09:00 Subject: Re: using 'require' Peter Bailey wrote: > A simple question . . . > > I wrote a little Ruby script that defines budgetary periods during the > course of a year. This is for my company's budget schedule. There are 13 > budget periods during any year. Anyway, I did this script. It seems to > work. I tested it and I can do a "put" of whatever budget period it is > now. > > I'd like to use this code in other scripts. It's named > "BNAbudgetperiods.rb." So, I did a require 'BNAbudgetperiods' in one of > my other scripts. But, when I do a put in that second script, it just > gives me "nil." It doesn't complain. It just gives me "nil." Is there > something special I need to do in the hierarchy of Ruby script locations > so that other scripts can respect any other script I want to require? > These two scripts are in the same directory. > > Thanks, > Peter Ruby searches for required files in a search path that is defined when you install Ruby. You can see what directories are in the search path by entering this command: ruby -e"puts $:" You can either put your script in a directory in the search path, or you can modify the search path by adding directories to it. There are two ways to modify the search path: A) set the RUBYLIB environment variable to a list of colon-delimited directories. Each directory in the list will be added to the front of the search path. export RUBYLIB=/home/me/my/scripts/dir or set RUBYLIB=C:\my\scripts\dir B) use the -I option when you run your script. You can specify -I more than once if necessary. ruby -I my/scripts/dir myscript.rb -- Posted via http://www.ruby-forum.com/.