This is a legacy RCR. If this is your RCR, please resubmit it using the new format and process.
I propose that 'require' loads files relative to the directory of the current file.
Ruby's 'require' cannot load 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.
Could we have:
require_local 'file_in_the_same_dir'
or
require 'file_in_the_same_dir', :local=>true
If we allow 'require' to load relative to the current source file, then we can just download and expand a .tgz and run, without a need to either install it or change the working directory. Also, we could use many multi-file projects without installing them into site_ruby/ or expanding $LOAD_PATH ad infinitum.
Why Patching Is Not Good Enough:
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, or if an installed library also has 'utils').
$LOAD_PATH
Another solution is to prepend the current file's directory before every
'require', which is too verbose, repetative, and error prone (think symlinks).
require 'pathname'
dir = Pathname.new(File.expand_path(__FILE__)).realpath
require File.join(dir, 'utils' ) # UGLY
I would also like to ask why this is NOT a standard feature of 'require'.
Back to RCRchive.
RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog
$LOAD_PATH <&lt;File.dirname($0) # BAD, does not work for libs<br /> $LOAD_PATH <&lt;File.dirname(__FILE__) # Also BAD, huge LOAD_PATH<br />