Z
Zoran Lazarevic
One of the most irritating (missing) features of Ruby is inability to
'require' files in the same directory or subdirectories as the
executing source file. In other programming languages (Java, C, C++)
that is commonly used. Note that this is different from the current
woriking directory.
I do not want to add the directory of the currenty executing file to
the library path because that would apply to all the other files,
including standard library (e.g. I usually have 'utils.rb' in every
project, and that would make a confusion if I tried to use two
projects).
$LOAD_PATH << File.dirname($0) # VERY BAD - does not work for
libs
$LOAD_PATH << File.dirname(__FILE__) # Also VERY BAD - huge
LOAD_PATH
The solution is to prepend current file's directory before every
'require', which is very ugly.
require File.join(File.dirname(__FILE__), 'utils' ) # UGLY
My question is:
- Why aren't required files looked up in subdirectories relative to
the current file?
- Is there an easy way to simulate that in Ruby?
- Can it be easily fixed in Ruby interpreter source code?
Thanks,
--Laza
'require' files in the same directory or subdirectories as the
executing source file. In other programming languages (Java, C, C++)
that is commonly used. Note that this is different from the current
woriking directory.
I do not want to add the directory of the currenty executing file to
the library path because that would apply to all the other files,
including standard library (e.g. I usually have 'utils.rb' in every
project, and that would make a confusion if I tried to use two
projects).
$LOAD_PATH << File.dirname($0) # VERY BAD - does not work for
libs
$LOAD_PATH << File.dirname(__FILE__) # Also VERY BAD - huge
LOAD_PATH
The solution is to prepend current file's directory before every
'require', which is very ugly.
require File.join(File.dirname(__FILE__), 'utils' ) # UGLY
My question is:
- Why aren't required files looked up in subdirectories relative to
the current file?
- Is there an easy way to simulate that in Ruby?
- Can it be easily fixed in Ruby interpreter source code?
Thanks,
--Laza