diff --git a/lib/irb/command/ls.rb b/lib/irb/command/ls.rb index eae643ff4..0ffea144f 100644 --- a/lib/irb/command/ls.rb +++ b/lib/irb/command/ls.rb @@ -72,8 +72,8 @@ def dump_methods(o, klass, obj) singleton_class = begin Kernel.instance_method(:singleton_class).bind(obj).call; rescue TypeError; nil end dumped_mods = Array.new ancestors = klass.ancestors - ancestors = ancestors.reject { |c| c >= Object } if klass < Object - singleton_ancestors = (singleton_class&.ancestors || []).reject { |c| c >= Class } + ancestors = ancestors.reject { |c| Object <= c } if Object > klass + singleton_ancestors = (singleton_class&.ancestors || []).reject { |c| Class <= c } # singleton_class' ancestors should be at the front maps = class_method_map(singleton_ancestors, dumped_mods) + class_method_map(ancestors, dumped_mods) diff --git a/test/irb/test_command.rb b/test/irb/test_command.rb index fd98a5a1b..e032f9d69 100644 --- a/test/irb/test_command.rb +++ b/test/irb/test_command.rb @@ -757,6 +757,16 @@ def test_ls_with_no_singleton_class assert_match(/Numeric#methods:\s+/, out) assert_match(/Integer#methods:\s+/, out) end + + def test_ls_with_object_altering_comparison_methods + out, err = execute_lines( + "class BadCompare; class << self; undef >=; undef <; end; def foo; end; end\n", + "obj = BadCompare.new\n", + "ls obj\n", + ) + assert_empty err + assert_match(/BadCompare#methods:\s+foo/, out) + end end class ShowDocTest < CommandTestCase