class Pry::Command::Ls

Constants

DEFAULT_OPTIONS

Public Instance Methods

no_user_opts?() click to toggle source

Exclude -q, -v and –grep because they, don't specify what the user wants to see.

# File lib/pry/commands/ls.rb, line 72
def no_user_opts?
  !(opts[:methods] || opts['instance-methods'] || opts[:ppp] ||
    opts[:globals] || opts[:locals] || opts[:constants] || opts[:ivars])
end
options(opt) click to toggle source
# File lib/pry/commands/ls.rb, line 52
def options(opt)
  opt.on :m, :methods,   "Show public methods defined on the Object"
  opt.on :M, "instance-methods", "Show public 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 77
def process
  @interrogatee = args.empty? ? target_self : target.eval(args.join(' '))
  raise_errors_if_arguments_are_weird
  ls_entity = LsEntity.new({
    :interrogatee => @interrogatee,
    :no_user_opts => no_user_opts?,
    :opts => opts,
    :args => args,
    :_pry_ => _pry_
  })

  _pry_.pager.page ls_entity.entities_table
end

Private Instance Methods

error_list() click to toggle source
# File lib/pry/commands/ls.rb, line 93
def error_list
  any_args = args.any?
  non_mod_interrogatee = !(Module === @interrogatee)
  [
    ['-l does not make sense with a specified Object', :locals, any_args],
    ['-g does not make sense with a specified Object', :globals, any_args],
    ['-q does not make sense with -v',                 :quiet, opts.present?(:verbose)],
    ['-M only makes sense with a Module or a Class',   'instance-methods', non_mod_interrogatee],
    ['-c only makes sense with a Module or a Class',   :constants, any_args && non_mod_interrogatee]
  ]
end
raise_errors_if_arguments_are_weird() click to toggle source
# File lib/pry/commands/ls.rb, line 105
def raise_errors_if_arguments_are_weird
  error_list.each do |message, option, invalid_expr|
    raise Pry::CommandError, message if opts.present?(option) && invalid_expr
  end
end