Image of Lucian Ghinda writing for notes.ghinda.com
November 7th, 2024

ruby/debug - a small tip to print variable before breakpoint

A small tip: when using the Ruby debug gem

To shorten the debug time, I like to add a puts <var> at the end of binding.break.

i will also display information about all variables, but when there are many, it is easier to display the last one and then look up.

Code sample about how to add breaking endpoint
Code sample about how to add breaking endpoint

There is also the option to not use puts but directly call a: 

binding.break(pre: 'ls ;; i ;; a')

But adding a puts or even a p to print the variable will remove some collisions with debug own commands.Â