unknown
5/9/2005 10:09:00 PM
Hi! Say I have a script called "gen.rb", and I would like it
to load a script called "loadme.rb" because it provides a common
routine used by a lot of scripts, but I don't want to install
it anywhere in the search path... I just want to keep it with
all the .rb files that actually use it... How do I specify
the directory that 'this' current script is in?
For example, I have:
c:\src\gen.rb
c:\src\loadme.rb
where gen.rb is:
--------------------------------------
#!/usr/bin/env ruby
dir=File.dirname(__FILE__)
load "#{dir}/loadme.rb"
puts "__FILE__=#{__FILE__}, $0=#{$0}"
--------------------------------------
Then I try this:
c:\src\somewhere\else> ruby ..\..\gen.rb
__FILE__=../../gen.rb, $0=../../gen.rb
This works, but is there a better way to include a file that
exists in the same directory as the original script?
Thanks!
-- Glenn