P
Patrick Doyle
[Note: parts of this message were removed to make it a legal post.]
I started looking through the source code for rake and noticed something
curious.
I see that when I execute the "rake" command at the command prompt, I run a
fairly trivial ruby script:
require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end
gem 'rake', version
load 'rake'
The #gem method prepended "..../gems/rake-0.8.3/bin" and
".../gems/rake-0.8.3/lib" to my $LOAD_PATH (the "bin" directory first).
Thus, when the script invokes the #load method, it grabs
"..../gems/rake-0.8.3/bin/rake" and starts to execute it. It looks like
this:
begin
require 'rake'
rescue LoadError
require 'rubygems'
require 'rake'
end
Rake.application.run
Somehow, the "#require" method knows that it should load the "rake.rb" file
from the "lib" directory (the second element in $LOAD_PATH) instead of the
already loaded "rake" from the "bin" directory, (the fist element in
$LOAD_PATH).
Why is that?
--wpd
I started looking through the source code for rake and noticed something
curious.
I see that when I execute the "rake" command at the command prompt, I run a
fairly trivial ruby script:
require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end
gem 'rake', version
load 'rake'
The #gem method prepended "..../gems/rake-0.8.3/bin" and
".../gems/rake-0.8.3/lib" to my $LOAD_PATH (the "bin" directory first).
Thus, when the script invokes the #load method, it grabs
"..../gems/rake-0.8.3/bin/rake" and starts to execute it. It looks like
this:
begin
require 'rake'
rescue LoadError
require 'rubygems'
require 'rake'
end
Rake.application.run
Somehow, the "#require" method knows that it should load the "rake.rb" file
from the "lib" directory (the second element in $LOAD_PATH) instead of the
already loaded "rake" from the "bin" directory, (the fist element in
$LOAD_PATH).
Why is that?
--wpd