summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/irb/cmd/ls.rb14
-rw-r--r--test/irb/test_cmd.rb26
2 files changed, 20 insertions, 20 deletions
diff --git a/lib/irb/cmd/ls.rb b/lib/irb/cmd/ls.rb
index 8a3c420f19..cfe513eb5f 100644
--- a/lib/irb/cmd/ls.rb
+++ b/lib/irb/cmd/ls.rb
@@ -17,28 +17,20 @@ module IRB
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 583e13278b..1d3a9e48af 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -377,23 +377,30 @@ module TestIRB
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
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