Is this a bug?
Shouldn’t ‘require’ load both modules in this case?
If not, what is the motivation for doing so?
Just curious
···
–
Simon Strandgaard
ls
a.rb
expand -t2 a.rb
require ‘fileutils’
code = <<RUBY
puts “hello”
RUBY
FileUtils.mkdir(“dir”)
File.open(“mod.rb”, “w+”) do |f|
f.write <<-RUBY
puts “hello1”
RUBY
end
FileUtils.cd(“dir”) do
File.open(“mod.rb”, “w+”) do |f|
f.write <<-RUBY
puts “hello2”
RUBY
end
end
require ‘mod’
$:.unshift(‘dir’)
require ‘mod’
ruby a.rb
hello1
ls
a.rb dir/ mod.rb
I would have expected it to output both ‘hello1’ and ‘hello2’.
Is this a bug?
Shouldn’t ‘require’ load both modules in this case?
If not, what is the motivation for doing so?
Just curious
–
Simon Strandgaard
[snip]
require ‘mod’
$:.unshift(‘dir’)
require ‘mod’
ruby a.rb
hello1
ls
a.rb dir/ mod.rb
I would have expected it to output both ‘hello1’ and ‘hello2’.
Hello Simon!
When requiring a module twice, it is probable that ruby just use its
name to check if it has to reload it or not, forgetting to also check if
it is in a different directory or not.
You can do this instead:
require ‘mod’
require ‘dir/mod’
Is this a bug?
Shouldn’t ‘require’ load both modules in this case?
If not, what is the motivation for doing so?
Just curious
–
Simon Strandgaard
[snip]
require ‘mod’
$:.unshift(‘dir’)
require ‘mod’
ruby a.rb
hello1
ls
a.rb dir/ mod.rb
I would have expected it to output both ‘hello1’ and ‘hello2’.
Hello Simon!
When requiring a module twice, it is probable that ruby just use its
name to check if it has to reload it or not, forgetting to also check if
it is in a different directory or not.
It seems so.
You can do this instead:
require ‘mod’
require ‘dir/mod’
I’m already aware of that
···
On Wed, 10 Mar 2004 15:23:08 +0100, shasckaw wrote:
The alternative is to use ‘load’ instead of ‘require’ which forces the interpreter to reload
the file if it has changed. YMMV.
Kind regards,
Dennis Oelkers
···
In pan.2004.03.10.14.13.43.358057@adslhome.dk Simon Strandgaard neoneye@adslhome.dk wrote:
On Wed, 10 Mar 2004 15:23:08 +0100, shasckaw wrote:
When requiring a module twice, it is probable that ruby just use its
name to check if it has to reload it or not, forgetting to also check if
it is in a different directory or not.
“Simon Strandgaard” neoneye@adslhome.dk schrieb im Newsbeitrag
news:pan.2004.03.10.14.13.43.358057@adslhome.dk…
Simon Strandgaard wrote:
Is this a bug?
Shouldn’t ‘require’ load both modules in this case?
If not, what is the motivation for doing so?
Just curious
–
Simon Strandgaard
[snip]
require ‘mod’
$:.unshift(‘dir’)
require ‘mod’
ruby a.rb
hello1
ls
a.rb dir/ mod.rb
I would have expected it to output both ‘hello1’ and ‘hello2’.
Hello Simon!
When requiring a module twice, it is probable that ruby just use its
name to check if it has to reload it or not, forgetting to also check
if
I don’t think that “forget” is the appropriate term. One of the files
named ‘mod.rb’ wins and gets loaded. If location would matter, all
mod.rb’s would have to be loaded, don’t they?
it is in a different directory or not.
It seems so.
Moreover IMHO this is the only approach to go. Doing “require ‘foo’”
announces that a “foo.rb” (or shared lib) has to be loaded from any
directory in $:. I guess the first occurrence wins. If there is another
foo.rb that is silently ignored. If at a later point in time either $:
changes or there is a new foo.rb in an earlier location in $:
Additionally it’s not usual that $: changes or that there are more files
with the same relative path in an installation’s lib directories. If
you create a situation like you did, it is IMHO more appropriate to use
“load” since you know where to get the file from anyway.
In short, I don’t regard this an error. Sorry if I haven’t been clear
enough. (Out of words error)
Kind regards
robert
···
On Wed, 10 Mar 2004 15:23:08 +0100, shasckaw wrote:
The alternative is to use ‘load’ instead of ‘require’ which forces the
interpreter to reload the file if it has changed. YMMV.
I am also aware of ‘load’… my intension with the piece of code I posted,
was a proof of concept. Not that I have problems using either load or
require.
Thanks for trying to help anyway
···
On Wed, 10 Mar 2004 15:28:37 +0100, Dennis Oelkers wrote:
In pan.2004.03.10.14.13.43.358057@adslhome.dk Simon Strandgaard neoneye@adslhome.dk wrote:
On Wed, 10 Mar 2004 15:23:08 +0100, shasckaw wrote: