class Pry::Command::Ls

Constants

BUILTIN_GLOBALS

ruby.runpaint.org/globals, and running "puts global_variables.inspect".

PSEUDO_GLOBALS

$SAFE and $? are thread-local, the exception stuff only works in a rescue clause, everything else is basically a local variable with a $ in its name.

Attributes

grep[R]
grep_regex[R]
has_user_specified_any_options[R]
object_to_interrogate[R]

Public Instance Methods

options(opt) click to toggle source
# File lib/pry/commands/ls.rb, line 8
def options(opt)
  opt.banner unindent <<-'BANNER'
    Usage: ls [-m|-M|-p|-pM] [-q|-v] [-c|-i] [Object]
           ls [-g] [-l]

    ls shows you which methods, constants and variables are accessible to Pry. By
    default it shows you the local variables defined in the current shell, and any
    public methods or instance variables defined on the current object.

    The colours used are configurable using Pry.config.ls.*_color, and the separator
    is Pry.config.ls.separator.

    Pry.config.ls.ceiling is used to hide methods defined higher up in the
    inheritance chain, this is by default set to [Object, Module, Class] so that
    methods defined on all Objects are omitted. The -v flag can be used to ignore
    this setting and show all methods, while the -q can be used to set the ceiling
    much lower and show only methods defined on the object or its direct class.
  BANNER

  opt.on :m, :methods,   "Show public methods defined on the Object (default)"
  opt.on :M, "instance-methods", "Show methods defined in a Module or Class"
  opt.on :p, :ppp,       "Show public, protected (in yellow) and private (in green) methods"
  opt.on :q, :quiet,     "Show only methods defined on object.singleton_class and object.class"
  opt.on :v, :verbose,   "Show methods and constants on all super-classes (ignores Pry.config.ls.ceiling)"
  opt.on :g, :globals,   "Show global variables, including those builtin to Ruby (in cyan)"
  opt.on :l, :locals,    "Show hash of local vars, sorted by descending size"
  opt.on :c, :constants, "Show constants, highlighting classes (in blue), and exceptions (in purple).\n" +
  " " * 32 +             "Constants that are pending autoload? are also shown (in yellow)"
  opt.on :i, :ivars,     "Show instance variables (in blue) and class variables (in bright blue)"
  opt.on :G, :grep,      "Filter output by regular expression", :argument => true

  if jruby?
    opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
  end
end
process() click to toggle source
# File lib/pry/commands/ls.rb, line 46
def process
  @object_to_interrogate = args.empty? ? target_self : target.eval(args.join(" "))

  # exclude -q, -v and --grep because they don't specify what the user wants to see.
  @has_user_specified_any_options = (opts.present?(:methods) || opts.present?(:'instance-methods') || opts.present?(:ppp) ||
                                      opts.present?(:globals) || opts.present?(:locals) || opts.present?(:constants) ||
                                      opts.present?(:ivars))

  @grep_regex, @grep = [Regexp.new(opts[:G] || "."), lambda{ |x| x.grep(@grep_regex) }]

  raise_errors_if_arguments_are_weird

  all_output = [
    write_out_globals,
    write_out_constants,
    write_out_methods,
    write_out_self_methods,
    write_out_ivars,
    write_out_local_names,
    write_out_locals,
  ].compact.join("")

  stagger_output(all_output)
end