Class: Byebug::EvalCommand

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



41
42
43
44
45
46
47
# File 'lib/byebug/commands/eval.rb', line 41

def description
  %{(p|e[val]) expression

    Evaluate expression and print its value
    * NOTE - unknown input is automatically evaluated, to turn this off
    use 'set noautoeval'}
end

.namesObject



37
38
39
# File 'lib/byebug/commands/eval.rb', line 37

def names
  %w(p eval)
end

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/byebug/commands/eval.rb', line 23

def execute
  expr = @match ? @match.post_match : @input
  run_with_binding do |b|
    if Setting[:stack_on_error]
      print "#{bb_eval(expr, b).inspect}\n"
    else
      print "#{bb_warning_eval(expr, b).inspect}\n"
    end
  end
rescue
  print "#{$!.class} Exception: #{$!.message}\n"
end

#match(input) ⇒ Object



14
15
16
17
# File 'lib/byebug/commands/eval.rb', line 14

def match(input)
  @input = input
  super
end

#regexpObject



19
20
21
# File 'lib/byebug/commands/eval.rb', line 19

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