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.



44
45
46
# File 'lib/byebug/helpers/eval.rb', line 44

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



28
29
30
# File 'lib/byebug/helpers/eval.rb', line 28

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



12
13
14
15
16
# File 'lib/byebug/helpers/eval.rb', line 12

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.



36
37
38
# File 'lib/byebug/helpers/eval.rb', line 36

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.



52
53
54
# File 'lib/byebug/helpers/eval.rb', line 52

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