Module: Byebug::EvalFunctions

Included in:
EvalCommand, PPCommand, PSCommand, PutLCommand
Defined in:
lib/byebug/commands/eval.rb

Overview

Utilities used by the eval command

Instance Method Summary collapse

Instance Method Details

#allowing_other_threadsObject

Run block temporarily ignoring all TracePoint events.

Used to evaluate stuff within Byebug’s prompt. Otherwise, any code creating new threads won’t be properly evaluated because new threads will get blocked by byebug’s main thread.



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

def allowing_other_threads
  Byebug.unlock
  res = yield
  Byebug.lock
  res
end

#eval_with_setting(binding, expression, stack_on_error) ⇒ Object

Evaluate expression using binding

Parameters:

  • binding (Binding)

    Context where to evaluate the expression

  • expression (String)

    Expression to evaluation

  • stack_on_error (Boolean)

    Whether to show a stack trace on error.



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

def eval_with_setting(binding, expression, stack_on_error)
  allowing_other_threads do
    if stack_on_error
      bb_eval(expression, binding)
    else
      bb_warning_eval(expression, binding)
    end
  end
end

#run_with_binding {|binding| ... } ⇒ Object

Get current binding and yield it to the given block

Yields:

  • (binding)


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

def run_with_binding
  binding = get_binding
  yield binding
end