mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Sort ls result ordered by anscestry
https://github.com/ruby/irb/commit/fdd5c0a71e
This commit is contained in:
parent
bce0021f75
commit
de779f4a62
2 changed files with 22 additions and 22 deletions
|
@ -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|
|
||||
|
|
|
@ -377,23 +377,30 @@ module TestIRB
|
|||
|
||||
def test_ls
|
||||
input = TestInputMethod.new([
|
||||
"class C\n",
|
||||
" def m1() end\n",
|
||||
"end\n",
|
||||
|
||||
"module M\n",
|
||||
"class P\n",
|
||||
" def m() end\n",
|
||||
" def m2() end\n",
|
||||
"end\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
|
||||
|
|
Loading…
Reference in a new issue