Class: Byebug::EvalCommand

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

Overview

Evaluation of expressions 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

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


84
85
86
87
88
89
90
91
92
93
# File 'lib/byebug/commands/eval.rb', line 84

def description
  prettify <<-EOD
    e[val] <expression>

    Evaluates <expression> and prints its value.

    * NOTE - unknown input is automatically evaluated, to turn this off
    use 'set noautoeval'.
  EOD
end

.namesObject


80
81
82
# File 'lib/byebug/commands/eval.rb', line 80

def names
  %w(eval)
end

Instance Method Details

#executeObject


68
69
70
71
72
73
74
75
76
77
# File 'lib/byebug/commands/eval.rb', line 68

def execute
  expr = @match ? @match.post_match : @input
  run_with_binding do |b|
    res = eval_with_setting(b, expr, Setting[:stack_on_error])

    print pr('eval.result', expr: expr, result: res.inspect)
  end
rescue
  puts "#{$ERROR_INFO.class} Exception: #{$ERROR_INFO.message}"
end

#match(input) ⇒ Object


59
60
61
62
# File 'lib/byebug/commands/eval.rb', line 59

def match(input)
  @input = input
  super
end

#regexpObject


64
65
66
# File 'lib/byebug/commands/eval.rb', line 64

def regexp
  /^\s* e(?:val)? \s+/x
end