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