Module: Byebug::Helpers::EvalHelper
- Included in:
- BreakCommand, CatchCommand, CommandProcessor, DebugCommand, DisplayCommand, VarHelper, MethodCommand, VarCommand::ConstCommand
- Defined in:
- lib/byebug/helpers/eval.rb
Overview
Utilities to assist evaluation of code strings
Instance Method Summary collapse
-
#error_eval(str, binding = frame._binding) ⇒ Object
Evaluates a string containing Ruby code in a specific binding, handling the errors at an error level.
-
#multiple_thread_eval(expression) ⇒ Object
Evaluates an
expression
that might use or defer execution to threads other than the current one. -
#separate_thread_eval(expression) ⇒ Object
Evaluates an
expression
in a separate thread. -
#silent_eval(str, binding = frame._binding) ⇒ Object
Evaluates a string containing Ruby code in a specific binding, returning nil in an error happens.
-
#warning_eval(str, binding = frame._binding) ⇒ Object
Evaluates a string containing Ruby code in a specific binding, handling the errors at a warning level.
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
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.
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.
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 |