Class: IRB::Command::Ls
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Exceptions:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
IRB::Command::Base
|
Defined in: | lib/irb/command/ls.rb |
Class Method Summary
Base
- Inherited
Instance Attribute Summary
Base
- Inherited
Instance Method Summary
Base
- Inherited
Constructor Details
This class inherits a constructor from IRB::Command::Base
Instance Method Details
#class_method_map(classes, dumped_mods)
[ GitHub ]# File 'lib/irb/command/ls.rb', line 84
def class_method_map(classes, dumped_mods) dumped_methods = Array.new 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)
[ GitHub ]# File 'lib/irb/command/ls.rb', line 69
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_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) end end
#evaluate(code)
[ GitHub ]# File 'lib/irb/command/ls.rb', line 25
def evaluate(code) @irb_context.workspace.binding.eval(code) rescue Exception => e puts "#{e.class}: #{e.}" raise EvaluationError end
#execute(arg)
[ GitHub ]# File 'lib/irb/command/ls.rb', line 32
def execute(arg) if match = arg.match(/\A(?<target>.\s|)(-g|-G)\s(?<grep>.+)$/) target = match[:target] grep = Regexp.new(match[:grep]) elsif match = arg.match(/\A((?<target>.),|)\s*grep:(?<grep>.)/) # Legacy style `ls obj, grep: /regexp/` # Evaluation order should be eval(target) then eval(grep) target = match[:target] || '' grep_regexp_code = match[:grep] else target = arg.strip end if target.empty? obj = irb_context.workspace.main locals = irb_context.workspace.binding.local_variables else obj = evaluate(target) end if grep_regexp_code grep = evaluate(grep_regexp_code) end o = Output.new(grep: grep) 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) if locals o.print_result rescue EvaluationError end