Class: Pry::Command::Ls::LocalNames

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

Instance Attribute Summary

Attributes inherited from Formatter

#_pry_, #grep

Instance Method Summary collapse

Methods inherited from Formatter

#color, #format_value, #output_section, #write_out

Constructor Details

#initialize(no_user_opts, args, _pry_) ⇒ LocalNames

Returns a new instance of LocalNames



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

def initialize(no_user_opts, args, _pry_)
  super(_pry_)
  @no_user_opts = no_user_opts
  @args = args
  @sticky_locals = _pry_.sticky_locals
end

Instance Method Details

#correct_opts?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/pry/commands/ls/local_names.rb', line 12

def correct_opts?
  super || (@no_user_opts && @args.empty?)
end

#format(locals) ⇒ Object (private)



23
24
25
26
27
28
29
30
31
# File 'lib/pry/commands/ls/local_names.rb', line 23

def format(locals)
  locals.sort_by(&:downcase).map do |name|
    if @sticky_locals.include?(name.to_sym)
      color(:pry_var, name)
    else
      color(:local_var, name)
    end
  end
end

#output_selfObject



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

def output_self
  local_vars = grep.regexp[@target.eval('local_variables')]
  output_section('locals', format(local_vars))
end