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

ruby-changes:66556

From: Keiko <ko1@a...>
Date: Tue, 22 Jun 2021 22:33:03 +0900 (JST)
Subject: [ruby-changes:66556] de779f4a62 (master): [ruby/irb] Sort ls result ordered by anscestry

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

From de779f4a620f408b72004a06545455f5a51a8584 Mon Sep 17 00:00:00 2001
From: Keiko Kaneko <keiko.cda@g...>
Date: Sun, 20 Jun 2021 11:36:40 +0900
Subject: [ruby/irb] Sort ls result ordered by anscestry

https://github.com/ruby/irb/commit/fdd5c0a71e
---
 lib/irb/cmd/ls.rb    | 14 +++-----------
 test/irb/test_cmd.rb | 26 +++++++++++++++++---------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/lib/irb/cmd/ls.rb b/lib/irb/cmd/ls.rb
index 8a3c420..cfe513e 100644
--- a/lib/irb/cmd/ls.rb
+++ b/lib/irb/cmd/ls.rb
@@ -17,28 +17,20 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/ls.rb#L17
         klass  = (obj.class == Class || obj.class == Module ? obj : obj.class)
 
         o.dump("constants", obj.constants) if obj.respond_to?(:constants)
-        dump_singleton_methods(o, klass, obj)
-        dump_instance_methods(o, klass)
+        dump_methods(o, klass, obj)
         o.dump("instance variables", obj.instance_variables)
         o.dump("class variables", klass.class_variables)
         o.dump("locals", locals)
       end
 
-      def dump_singleton_methods(o, klass, obj)
-        maps = class_method_map(obj.singleton_class.ancestors.take_while { |c| c != klass })
+      def dump_methods(o, klass, obj)
+        maps = class_method_map(obj.singleton_class.ancestors)
         maps.each do |mod, methods|
           name = mod == obj.singleton_class ? "#{klass}.methods" : "#{mod}#methods"
           o.dump(name, methods)
         end
       end
 
-      def dump_instance_methods(o, klass)
-        maps = class_method_map(klass.ancestors)
-        maps.each do |mod, methods|
-          o.dump("#{mod}#methods", methods)
-        end
-      end
-
       def class_method_map(classes)
         dumped = Set.new
         classes.reject { |mod| mod >= Object }.map do |mod|
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index 583e132..1d3a9e4 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -377,23 +377,30 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L377
 
     def test_ls
       input = TestInputMethod.new([
-        "class C\n",
-        "  def m1() end\n",
+        "class P\n",
+        "  def m() end\n",
+        "  def m2() end\n",
         "end\n",
 
-        "module M\n",
+        "class C < P\n",
+        "  def m1() end\n",
         "  def m2() end\n",
         "end\n",
 
+        "module M\n",
+        "  def m1() end\n",
+        "  def m3() end\n",
+        "end\n",
+        
         "module M2\n",
         "  include M\n",
-        "  def m3() end\n",
+        "  def m4() end\n",
         "end\n",
 
         "obj = C.new\n",
         "obj.instance_variable_set(:@a, 1)\n",
         "obj.extend M2\n",
-        "def obj.m4() end\n",
+        "def obj.m5() end\n",
         "ls obj\n",
       ])
       IRB.init_config(nil)
@@ -407,10 +414,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L414
       end
       assert_empty err
       assert_match(/^instance variables:\s+@a\n/m, out)
-      assert_match(/C#methods:\s+m1\n/m, out)
-      assert_match(/M#methods:\s+m2\n/m, out)
-      assert_match(/M2#methods:\s+m3\n/m, out)
-      assert_match(/C.methods:\s+m4\n/m, out)
+      assert_match(/P#methods:\s+m\n/m, out)
+      assert_match(/C#methods:\s+m2\n/m, out)
+      assert_match(/M#methods:\s+m1\s+m3\n/m, out)
+      assert_match(/M2#methods:\s+m4\n/m, out)
+      assert_match(/C.methods:\s+m5\n/m, out)
     end
 
     def test_show_source
-- 
cgit v1.1


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

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