Skip to content

Commit 2af7c6b

Browse files
committed
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".
1 parent 005ade7 commit 2af7c6b

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/irb/completion.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ def self.retrieve_gem_and_system_load_path
6464
end
6565

6666
def self.retrieve_files_to_require_from_load_path
67-
@@files_from_load_path ||= retrieve_gem_and_system_load_path.map { |path|
68-
begin
69-
Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
70-
rescue Errno::ENOENT
71-
[]
72-
end
73-
}.inject([]) { |result, names|
74-
shortest, *rest = names.map{ |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort
75-
result.unshift(shortest) if shortest
76-
result.concat(rest)
77-
result
78-
}.uniq
67+
@@files_from_load_path ||=
68+
(
69+
shortest = []
70+
rest = retrieve_gem_and_system_load_path.each_with_object([]) { |path, result|
71+
begin
72+
names = Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
73+
rescue Errno::ENOENT
74+
nil
75+
end
76+
next if names.empty?
77+
names.map! { |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort!
78+
shortest << names.shift
79+
result.concat(names)
80+
}
81+
shortest.sort! | rest
82+
)
7983
end
8084

8185
def self.retrieve_files_to_require_relative_from_current_dir

0 commit comments

Comments
 (0)