6

Let's say I'm stopped on point while debugging:

def get_data
    byebug
 => @cache ||= calculate_data
end

And @cache has value, so on step function calculate_data won't be executed. But I need to check what's going on inside of calculate_data at this exact runtime point.

I can just execute calculate_data and see its result in console output, but can I execute function from debug console and at same time step into it? (Using byebug or some other debugging tool).

Goal - is to inspect calculate_data logic at arbitrary time, particularly when get_data called with @cache filled.

4
  • Then in that case you have to find calculate_data and put byebug in that method. github.com/deivid-rodriguez/byebug/blob/master/GUIDE.md Commented Dec 22, 2016 at 12:40
  • That's incorrect suggestion, because then I will stop on initial calculation (before @cache filled). But described goal - is to inspect calculate_data at specific runtime point, particularly when @cache is set. Commented Dec 22, 2016 at 13:14
  • Would love to know how to do that too! Commented Dec 29, 2016 at 1:19
  • I'm interested in this question too, because Capybara's DSL works in such dynamic way that even settings breakpoint to /capybara-2.18.0/lib/capybara/node/actions.rb:237 does not make it stop when I call attach_file. Commented Oct 16, 2018 at 11:08

1 Answer 1

3

With pry-moves you can execute separate debug of arbitrary function from current context:

def get_data
    binding.pry
 => @cache ||= calculate_data
end

Type debug calculate_data to run calculate_data and stop at first line inside of it.

Sign up to request clarification or add additional context in comments.

1 Comment

answering a question from 2016 I like the commitment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.