Learning more about pry
I'm constantly amazed about the things that I "know" but need to relearn in a practical sense daily.
One of those is all of the tools that are in the "pry" toolbox for ruby.
As anyone knows who has debugged ruby, sometimes just getting to the location of the issue can be a pain. Am I there yet? No, continue the program execution. Is the condition I'm looking for the current one? No, continue. Ugh.
One of the things that I love about programming is guard conditions. I can say something like
do_this if some_condition
It's a common idiom to exit the program early if some guard condition has been met.
One of the other interesting things, is how do I debug, and more specifically hit a breakpoint in some gem.
I was working on a client's code with exactly this issue the other day. I remembered that I can set a breakpoint with a full path somewhat like this:
break /some/directory/or/another/ruby.rb:25
and then looked in the docs and found that I can use a guard condition too.
break /some/directory/or/another/ruby.rb:25 if some_condition_is_true
That turned what could have been a few hours of tedium into about 10 minutes of power debugging and easily fixing the problem.
Thinking "big picture", what can I learn from this? Always go back and read the manual. It takes such a short amount of time to read in comparison to the work that I'm doing and I may be able to save large amounts of time just by reading the manual again to see how I might be able to solve the problem differently.