Skip to content

Commit 69b556c

Browse files
committed
Make ls command work for BasicObjects
1 parent 2990ac5 commit 69b556c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

lib/irb/command/ls.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,21 @@ def execute(arg)
5555

5656
o = Output.new(grep: grep)
5757

58-
klass = (obj.class == Class || obj.class == Module ? obj : obj.class)
58+
klass = Kernel.instance_method(:class).bind(obj).call
59+
is_class_or_module = klass == Class || klass == Module
60+
klass = is_class_or_module ? obj : klass
5961

60-
o.dump("constants", obj.constants) if obj.respond_to?(:constants)
62+
o.dump("constants", obj.constants) if is_class_or_module
6163
dump_methods(o, klass, obj)
62-
o.dump("instance variables", obj.instance_variables)
64+
o.dump("instance variables", Kernel.instance_method(:instance_variables).bind(obj).call)
6365
o.dump("class variables", klass.class_variables)
6466
o.dump("locals", locals) if locals
6567
o.print_result
6668
rescue EvaluationError
6769
end
6870

6971
def dump_methods(o, klass, obj)
70-
singleton_class = begin obj.singleton_class; rescue TypeError; nil end
72+
singleton_class = begin Kernel.instance_method(:singleton_class).bind(obj).call; rescue TypeError; nil end
7173
dumped_mods = Array.new
7274
ancestors = klass.ancestors
7375
ancestors = ancestors.reject { |c| c >= Object } if klass < Object

0 commit comments

Comments
 (0)