Class: IRB::ExtendCommand::Ls
Instance Attribute Summary
Attributes inherited from Nop
#irb_context
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Nop
category, description, execute, #initialize, #irb
Class Method Details
15
16
17
18
19
20
21
22
|
# File 'lib/irb/cmd/ls.rb', line 15
def self.transform_args(args)
if match = args&.match(/\A(?<args>.+\s|)(-g|-G)\s+(?<grep>[^\s]+)\s*\n\z/)
args = match[:args]
"#{args}#{',' unless args.chomp.empty?} grep: /#{match[:grep]}/"
else
args
end
end
|
Instance Method Details
#class_method_map(classes, dumped_mods) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/irb/cmd/ls.rb', line 50
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
dumped_mods << mod
methods = mod.public_instance_methods(false).select do |method|
if dumped_methods.include? method
false
else
dumped_methods << method
true
end
end
[mod, methods]
end.compact
end
|
#dump_methods(o, klass, obj) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/irb/cmd/ls.rb', line 39
def dump_methods(o, klass, obj)
singleton_class = begin obj.singleton_class; rescue TypeError; nil end
dumped_mods = Array.new
maps = class_method_map(singleton_class&.ancestors || [], dumped_mods) + class_method_map(klass.ancestors, dumped_mods)
maps.each do |mod, methods|
name = mod == singleton_class ? "#{klass}.methods" : "#{mod}#methods"
o.dump(name, methods)
end
end
|
#execute(*arg, grep: nil) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/irb/cmd/ls.rb', line 24
def execute(*arg, grep: nil)
o = Output.new(grep: grep)
obj = arg.empty? ? irb_context.workspace.main : arg.first
locals = arg.empty? ? irb_context.workspace.binding.local_variables : []
klass = (obj.class == Class || obj.class == Module ? obj : obj.class)
o.dump("constants", obj.constants) if obj.respond_to?(:constants)
dump_methods(o, klass, obj)
o.dump("instance variables", obj.instance_variables)
o.dump("class variables", klass.class_variables)
o.dump("locals", locals)
nil
end
|