Load resource relative to required file?

I looked in the faq and I couldn’t find my answer or a searchable
archive for the mailing list (so if anyone has that it would be
great).

I have a 1st.rb file that loads an xml configuration file that is in
the same directory. I have 2nd.rb file that uses the 1st.rb file via
require. Everything was fine when they were in the same directory,
but when I put 1st.rb in a subdirectory, it no longer loads its .xml
file (which has also moved to the subdirectory). I get a “No such
file or directory” error.

So the question is, how does one load a resource relative to the
actual file, and not the file that required it?

Walt

···

Walter Szewelanczyk
IS Director
M.W. Sewall & CO. email : walter@mwsewall.com
259 Front St. Phone : (207) 442-7994 x 128
Bath, ME 04530 Fax : (207) 443-6284


The attached file will do something like this for the font resources I use
in PDF::Writer (which I have been lazy about). I’m not sure that it’s
easy/possible to limit it just to the file currently required.

-austin

font.rb (3.79 KB)

···

On Wed, 23 Jul 2003 06:58:28 +0900, walter@mwsewall.com wrote:

I looked in the faq and I couldn’t find my answer or a searchable archive
for the mailing list (so if anyone has that it would be great).

I have a 1st.rb file that loads an xml configuration file that is in the
same directory. I have 2nd.rb file that uses the 1st.rb file via
require. Everything was fine when they were in the same directory, but
when I put 1st.rb in a subdirectory, it no longer loads its .xml file
(which has also moved to the subdirectory). I get a “No such file or
directory” error.

So the question is, how does one load a resource relative to the actual
file, and not the file that required it?


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.08.19
* 21.30.03