123456789_123456789_123456789_123456789_123456789_

Class: IRB::ExtendCommand::Ls

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Nop
Instance Chain:
self, Nop
Inherits: IRB::ExtendCommand::Nop
Defined in: lib/irb/cmd/ls.rb

Class Method Summary

Nop - Inherited

.category, .description,
.execute

See additional method definition at line 39.

.new, .string_literal?

Instance Attribute Summary

Nop - Inherited

Instance Method Summary

Constructor Details

This class inherits a constructor from IRB::ExtendCommand::Nop

Class Method Details

.transform_args(args)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# File 'lib/irb/cmd/ls.rb', line 48

def class_method_map(classes)
  dumped = Array.new
  classes.reject { |mod| mod >= Object }.map do |mod|
    methods = mod.public_instance_methods(false).select do |m|
      dumped.push(m) unless dumped.include?(m)
    end
    [mod, methods]
  end.reverse
end

#dump_methods(o, klass, obj)

[ GitHub ]

  
# File 'lib/irb/cmd/ls.rb', line 39

def dump_methods(o, klass, obj)
  singleton_class = begin obj.singleton_class; rescue TypeError; nil end
  maps = class_method_map((singleton_class || klass).ancestors)
  maps.each do |mod, methods|
    name = mod == singleton_class ? "#{klass}.methods" : "#{mod}#methods"
    o.dump(name, methods)
  end
end

#execute(*arg, grep: nil)

[ GitHub ]

  
# 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