Class: Byebug::PSCommand

Inherits:
Command show all
Includes:
EvalFunctions, Columnize
Defined in:
lib/byebug/commands/eval.rb

Overview

Evaluation, pretty printing, columnizing and sorting from byebug's prompt

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EvalFunctions

#allowing_other_threads, #eval_with_setting, #run_with_binding

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, #match

Methods included from StringFunctions

#camelize, #prettify

Methods included from FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Methods included from ParseFunctions

#get_int, #parse_steps, #syntax_valid?

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject


216
217
218
219
220
221
222
# File 'lib/byebug/commands/eval.rb', line 216

def description
  prettify <<-EOD
    ps <expression>

    Evaluates <expression>, an array, sort and columnize its value.
  EOD
end

.namesObject


212
213
214
# File 'lib/byebug/commands/eval.rb', line 212

def names
  %w(ps)
end

Instance Method Details

#executeObject


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/byebug/commands/eval.rb', line 195

def execute
  out = StringIO.new
  run_with_binding do |b|
    res = eval_with_setting(b, @match.post_match, Setting[:stack_on_error])

    if res.is_a?(Array)
      puts "#{columnize(res.map(&:to_s).sort!, Setting[:width])}"
    else
      PP.pp(res, out)
      puts out.string
    end
  end
rescue
  out.puts $ERROR_INFO.message
end

#regexpObject


191
192
193
# File 'lib/byebug/commands/eval.rb', line 191

def regexp
  /^\s* ps \s+/x
end