Here is Rolando's solution:
module Kernel
alias kernel_original_require require
FILE_EXTENSIONS = [".so", ".bundle", ".dll"]
def check_require2(lib, path)
$_req_disp_table ||= {}
if File.file?(path)
if $_req_disp_table[lib].nil?
puts " require '#{lib}' => #{path}"
$_req_disp_table[lib] = 1
end
return true
else
return false
end
end
def check_require(lib, path)
if (ext = File.extname(path)).empty? || ext == ".rb"
# puts ">>> #{path} does not have an extension"
ext = ".rb"
[".rb"].concat FILE_EXTENSIONS
else
# puts ">>> #{path} has extension"
FILE_EXTENSIONS
end.each { |_ext|
res = check_require2(lib, File.join(File.dirname(path),
File.basename(path, ext) + _ext))
return res if res
}
return false
end
def require(lib)
# puts ">>> requiring #{lib} (#{$_req_top})
(#{$_req_table.inspect})"
$_req_top ||= lib
if (ENV['REQUIRE_SHOW_ALL'].nil? && lib == $_req_top) ||
ENV['REQUIRE_SHOW_ALL']
got_it = false
$:.each { |d|
fpath = File.join(d, lib)
got_it = check_require(lib, fpath)
break if got_it
}
end
if (res = kernel_original_require(lib)) && got_it
$_req_top = nil
end
res
end
end
if __FILE__ == $0
ARGV.each { |m| require m }
end