[前][次][番号順一覧][スレッド一覧]

ruby-changes:68061

From: Nobuyoshi <ko1@a...>
Date: Tue, 21 Sep 2021 23:28:25 +0900 (JST)
Subject: [ruby-changes:68061] ee53d97b16 (master): [ruby/irb] Sort shortest files in each load paths

https://git.ruby-lang.org/ruby.git/commit/?id=ee53d97b16

From ee53d97b16fdf13e14e1a4a89c31e2a621ddbd66 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 17 Sep 2021 20:30:16 +0900
Subject: [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
---
 lib/irb/completion.rb | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index 5752102..7403489 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -64,18 +64,22 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L64
     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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]