Class: Pry::Command::Ls::LocalVars

Inherits:
Formatter show all
Defined in:
lib/pry/commands/ls/local_vars.rb

Instance Attribute Summary

Attributes inherited from Formatter

#_pry_, #grep

Instance Method Summary collapse

Methods inherited from Formatter

#color, #correct_opts?, #format_value, #output_section, #write_out

Constructor Details

#initialize(opts, _pry_) ⇒ LocalVars

Returns a new instance of LocalVars



5
6
7
8
9
# File 'lib/pry/commands/ls/local_vars.rb', line 5

def initialize(opts, _pry_)
  super(_pry_)
  @default_switch = opts[:locals]
  @sticky_locals = _pry_.sticky_locals
end

Instance Method Details

#colorized_assignment_style(lhs, rhs, desired_width = 7) ⇒ Object (private)



30
31
32
33
34
35
# File 'lib/pry/commands/ls/local_vars.rb', line 30

def colorized_assignment_style(lhs, rhs, desired_width = 7)
  colorized_lhs = color(:local_var, lhs)
  color_escape_padding = colorized_lhs.size - lhs.size
  pad = desired_width + color_escape_padding
  "%-#{pad}s = %s" % [color(:local_var, colorized_lhs), rhs]
end

#format(name_value_pairs) ⇒ Object (private)



22
23
24
25
26
27
28
# File 'lib/pry/commands/ls/local_vars.rb', line 22

def format(name_value_pairs)
  name_value_pairs.sort_by { |name, value|
    value.to_s.size
  }.reverse.map { |name, value|
    colorized_assignment_style(name, format_value(value))
  }
end

#output_selfObject



11
12
13
14
15
16
17
18
# File 'lib/pry/commands/ls/local_vars.rb', line 11

def output_self
  name_value_pairs = @target.eval('local_variables').reject { |e|
    @sticky_locals.keys.include?(e.to_sym)
  }.map { |name|
    [name, (@target.eval(name.to_s))]
  }
  format(name_value_pairs).join('')
end