class Pry::Command::Ls::Constants

Public Class Methods

new(interrogatee, no_user_opts, opts, _pry_) click to toggle source
Calls superclass method Pry::Command::Ls::Formatter.new
# File lib/pry/commands/ls/constants.rb, line 9
def initialize(interrogatee, no_user_opts, opts, _pry_)
  super(_pry_)
  @interrogatee = interrogatee
  @no_user_opts = no_user_opts
  @default_switch = opts[:constants]
  @verbose_switch = opts[:verbose]
end

Public Instance Methods

correct_opts?() click to toggle source
# File lib/pry/commands/ls/constants.rb, line 17
def correct_opts?
  super || (@no_user_opts && interrogating_a_module?)
end
output_self() click to toggle source
# File lib/pry/commands/ls/constants.rb, line 21
def output_self
  mod = interrogatee_mod
  constants = WrappedModule.new(mod).constants(@verbose_switch)
  output_section('constants', grep.regexp[format(mod, constants)])
end

Private Instance Methods

format(mod, constants) click to toggle source
# File lib/pry/commands/ls/constants.rb, line 29
def format(mod, constants)
  constants.sort_by(&:downcase).map do |name|
    if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)
      if (const < Exception rescue false)
        color(:exception_constant, name)
      elsif (Module === mod.const_get(name) rescue false)
        color(:class_constant, name)
      else
        color(:constant, name)
      end
    else
      color(:unloaded_constant, name)
    end
  end
end