Module: Byebug::Helpers::EvalHelper

Overview

Utilities to assist evaluation of code strings

Instance Method Summary collapse

Instance Method Details

#error_eval(str, binding = frame._binding) ⇒ Object

Evaluates a string containing Ruby code in a specific binding, handling the errors at an error level.



46
47
48
# File 'lib/byebug/helpers/eval.rb', line 46

def error_eval(str, binding = frame._binding)
  safe_eval(str, binding) { |e| raise(e, msg(e)) }
end

#multiple_thread_eval(expression) ⇒ Object

Note:

This is necessary because when in byebug’s prompt, every thread is

Evaluates an expression that might use or defer execution to threads other than the current one.

“frozen” so that nothing gets run. So we need to unlock threads prior to evaluation or we will run into a deadlock.

Parameters:

  • expression (String)

    Expression to evaluate



30
31
32
# File 'lib/byebug/helpers/eval.rb', line 30

def multiple_thread_eval(expression)
  allowing_other_threads { warning_eval(expression) }
end

#separate_thread_eval(expression) ⇒ Object

Evaluates an expression in a separate thread.

Parameters:

  • expression (String)

    Expression to evaluate



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

def separate_thread_eval(expression)
  allowing_other_threads do
    in_new_thread { warning_eval(expression) }
  end
end

#silent_eval(str, binding = frame._binding) ⇒ Object

Evaluates a string containing Ruby code in a specific binding, returning nil in an error happens.



38
39
40
# File 'lib/byebug/helpers/eval.rb', line 38

def silent_eval(str, binding = frame._binding)
  safe_eval(str, binding) { |_e| nil }
end

#warning_eval(str, binding = frame._binding) ⇒ Object

Evaluates a string containing Ruby code in a specific binding, handling the errors at a warning level.



54
55
56
# File 'lib/byebug/helpers/eval.rb', line 54

def warning_eval(str, binding = frame._binding)
  safe_eval(str, binding) { |e| errmsg(msg(e)) }
end