duplicated require of '.so' files?
We are trying to get rid of autoload;
We could require everything in the first line of the file but instead we
prefer to require only what we need, when we need it.
So, instead of
we would like to do:
The problem we've found, is that duplicate
require(name), satisfied by
".rb" files are only executed once; but when file loaded by
require(name) is a '.so', next requires with the same name will be
executed again and again.
$ cat require-rb.rb
$ strace -e trace=file -o require-rb.log ruby require-rb.rb
$ grep -c -E 'open.*/set' require-rb.log
$ cat require-so.rb
$ strace -e trace=file -o require-so.log ruby require-so.rb
$ grep -c -E 'open.*/md5' require-so.log
Is this a bug or a feature?
Updated by nagachika (Tomoyuki Chikanaga) almost 6 years ago
- Status changed from Open to Rejected
It is not a bug.
At first, please take a look at the script belows.
$LOAD_PATH << "." File.unlink "dbm.rb" if File.exist?("dbm.rb") p require "dbm" open("dbm.rb", "w") do |f| f.puts(<<-EOF) p "local dbm.rb is loaded" EOF end p require "dbm"
true "local dbm.rb is loaded" true
Kernel#require search a script/extention library file in $LOAD_PATH directories in order.
Even though the feature was already loaded, Kernel#require search $LOAD_PATH for a new file which have higher priority.
In your example, require "digest/md5" search under site_ruby, vendor_ruby etc.