Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby: How to step into arbitrary function while debugging

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.

like image 873
Daniel Garmoshka Avatar asked Dec 22 '16 12:12

Daniel Garmoshka


1 Answers

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.

like image 110
Daniel Garmoshka Avatar answered Nov 03 '22 19:11

Daniel Garmoshka