Class: Pry::Command::Ls::InstanceVars

Inherits:
Formatter show all
Includes:
Interrogatable
Defined in:
lib/pry/commands/ls/instance_vars.rb

Instance Attribute Summary

Attributes inherited from Formatter

#grep, #pry_instance

Instance Method Summary collapse

Methods included from Interrogatable

#interrogatee_mod, #interrogating_a_module?

Methods inherited from Formatter

#color, #format_value, #output_section, #write_out

Constructor Details

#initialize(interrogatee, no_user_opts, opts, pry_instance) ⇒ InstanceVars


9
10
11
12
13
14
# File 'lib/pry/commands/ls/instance_vars.rb', line 9

def initialize(interrogatee, no_user_opts, opts, pry_instance)
  super(pry_instance)
  @interrogatee = interrogatee
  @no_user_opts = no_user_opts
  @default_switch = opts[:ivars]
end

Instance Method Details

#correct_opts?Boolean


16
17
18
# File 'lib/pry/commands/ls/instance_vars.rb', line 16

def correct_opts?
  super || @no_user_opts
end

#format(type, vars) ⇒ Object (private)


34
35
36
# File 'lib/pry/commands/ls/instance_vars.rb', line 34

def format(type, vars)
  vars.sort_by { |var| var.to_s.downcase }.map { |var| color(type, var) }
end

#output_selfObject


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pry/commands/ls/instance_vars.rb', line 20

def output_self
  ivars = if Object === @interrogatee # rubocop:disable Style/CaseEquality
            Pry::Method.safe_send(@interrogatee, :instance_variables)
          else
            [] # TODO: BasicObject support
          end
  kvars = Pry::Method.safe_send(interrogatee_mod, :class_variables)
  ivars_out = output_section('instance variables', format(:instance_var, ivars))
  kvars_out = output_section('class variables', format(:class_var, kvars))
  ivars_out + kvars_out
end