Dreamcat Four wrote: > > Here is a fix to the require() and load() methods. Its easier to patch > it there and just not to assume those methods are being given relative > paths. > > http://github.com/dreamcat4/script/commit/e7d585b5 --- a/lib/script.rb +++ b/lib/script.rb @@ -52,7 +52,11 @@ class Script < Module # from those sub files. def load(file, wrap = false) - load_in_module(File.join(@__dir, file)) + if file =~ /^\// + load_in_module(file) + else + load_in_module(File.join(@__dir, file)) + end true rescue MissingFile super @@ -70,7 +74,11 @@ class Script < Module def require(feature) unless @__loaded_features[feature] @__loaded_features[feature] = true - file = File.join(@__dir, feature) + if feature =~ /^\// + file = feature + else + file = File.join(@__dir, feature) + end file += ".rb" unless /\.rb$/ =~ file load_in_module(file) end -- 1.6.6.1 > > Joel VanderWerf wrote: >> On Sun, Jul 11, 2010 at 3:07 AM, Dreamcat Four <dreamcat4 / gmail.com> >> wrote: >>> http://gist.github.com/471434 >>> >>> I noticed that there is a redefinition of require in script.rb. Is that >>> method meant to be handling that? >>> >>> http://redshift.sourceforge.net/script/doc/classes/Script.html#M000003 >> >> Yes. The problem is in the way your script references the other files. >> You've got absolute paths (which makes sense in the no-wrapper case), >> but the Script class is expecting relative. The problem goes away >> (AFAICT) with this patch: >> >> --- /home/vjoel/tmp/dc2/examples/scripts/script.rb 2010-07-13 >> 17:13:47.673562875 -0700 >> +++ - 2010-07-13 17:15:18.375246675 -0700 >> @@ -1,6 +1,6 @@ >> puts "in #{__FILE__}, line #{__LINE__}" >> >> -load File.dirname(__FILE__)+"/sub-script.rb" >> +load "sub-script.rb" >> >> OUTPUT = ["input was #{INPUT}"] >> >> @@ -9,10 +9,10 @@ >> end >> end >> >> -require File.dirname(__FILE__)+'/lib/a-class' >> +require 'lib/a-class' >> >> -require File.dirname(__FILE__)+'/lib/x-accessor' >> -require File.dirname(__FILE__)+'/lib/x-accessor' # only loaded once >> +require 'lib/x-accessor' >> +require 'lib/x-accessor' # only loaded once >> >> # Falls back to Kernel.load, since "benchmark.rb" isn't in the current >> dir. >> load "benchmark.rb" unless $LOADED_FEATURES.include?("benchmark.rb") -- Posted via http://www.ruby-forum.com/.