summaryrefslogtreecommitdiff
path: root/lib/irb
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-04-24 15:05:11 +0100
committergit <svn-admin@ruby-lang.org>2023-04-24 14:05:16 +0000
commit805899dda29e36a42ffd9e076b9296f3bf13af5a (patch)
treeedc70d418bd1419b25d1018e038b58d178bf6883 /lib/irb
parent886986b3efe157148e329957c7f236f0e35be0c2 (diff)
[ruby/irb] Filter out top-level methods when using `ls
<Class/Module>` (https://github.com/ruby/irb/pull/562) Instead of always printing methods inherited from Class or Module, IRB by default should filter them out unless `<Class/Module>` is specified to be either of those.
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/cmd/ls.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/irb/cmd/ls.rb b/lib/irb/cmd/ls.rb
index d5a371a4d6..063a88d33f 100644
--- a/lib/irb/cmd/ls.rb
+++ b/lib/irb/cmd/ls.rb
@@ -39,8 +39,12 @@ module IRB
def dump_methods(o, klass, obj)
singleton_class = begin obj.singleton_class; 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 }
+
# singleton_class' ancestors should be at the front
- maps = class_method_map(singleton_class&.ancestors || [], dumped_mods) + class_method_map(klass.ancestors, dumped_mods)
+ maps = class_method_map(singleton_ancestors, dumped_mods) + class_method_map(ancestors, dumped_mods)
maps.each do |mod, methods|
name = mod == singleton_class ? "#{klass}.methods" : "#{mod}#methods"
o.dump(name, methods)
@@ -49,7 +53,6 @@ module IRB
def class_method_map(classes, dumped_mods)
dumped_methods = Array.new
- classes = classes.reject { |mod| mod >= Object }
classes.map do |mod|
next if dumped_mods.include? mod