[ruby/irb] Sort shortest files in each load paths

There are two directories where csv*/**/*.rb exist, lib/ and
test/, and depending on the order of tests, test/ may be placed
before lib/.  In that case, as "shortest" names were not sorted,
csv/helper.rb will be the first candidate for "csv".

https://github.com/ruby/irb/commit/2af7c6bf71
This commit is contained in:
Nobuyoshi Nakada 2021-09-17 20:30:16 +09:00 committed by git
parent c94718e39f
commit ee53d97b16

View File

@ -64,18 +64,22 @@ module IRB
end end
def self.retrieve_files_to_require_from_load_path def self.retrieve_files_to_require_from_load_path
@@files_from_load_path ||= retrieve_gem_and_system_load_path.map { |path| @@files_from_load_path ||=
begin (
Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path) shortest = []
rescue Errno::ENOENT rest = retrieve_gem_and_system_load_path.each_with_object([]) { |path, result|
[] begin
end names = Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
}.inject([]) { |result, names| rescue Errno::ENOENT
shortest, *rest = names.map{ |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort nil
result.unshift(shortest) if shortest end
result.concat(rest) next if names.empty?
result names.map! { |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort!
}.uniq shortest << names.shift
result.concat(names)
}
shortest.sort! | rest
)
end end
def self.retrieve_files_to_require_relative_from_current_dir def self.retrieve_files_to_require_relative_from_current_dir