Which one is better at debugging in rails?
We can start a comparison by a very simple example via rails c.
binding.irbexample
def sum(a, b)
binding.irb
puts a
puts b
a + b
endbinding.pryexample
def sum(a, b)
binding.pry
puts a
puts b
a + b
endWhile binding.irb has a very interesting promise, like serving as the main debugger in rails, it comes with bugs and drawbacks that simply don't exist when we using binding.pry for the debugging process.
binding.pry looks more clear for the debugging process, particularly because binding.pry outputs to the user the code where binding.pry is located as soon as the code hits this debugger, while binding.irb doesn't output anything to the user when the code hits this debugger (even if we call whereami sometimes it doesn't output anything (😱), which is very confusing in terms of usability).
In addition, there are bugs in binding.irb related to not outputting the value of a variable when we call it! We can check it by looking at the above pictures and noticing the a variable value was not shown to the user here:
irb(main):004> aOn the other hand, binding.pry doesn't have this bug and always output the value of a variable when we call it and press enter.
As a last note... Is there a way to fix all of these bugs in binding.irb? In case not, I would recommend to keep using binding.pry for the debugging process to avoid headaches.


Markdown version without pictures
binding.irbXbinding.pry?Which one is better at debugging in rails?
Comparison
We can start a comparison by a very simple example via
rails c.binding.irbexamplebinding.pryexampleOutputs
binding.irbbinding.pryConclusion
While
binding.irbhas a very interesting promise, like serving as the main debugger in rails, it comes with bugs and drawbacks that simply don't exist when we usingbinding.pryfor the debugging process.1. Where am I ?!
binding.prylooks more clear for the debugging process, particularly becausebinding.pryoutputs to the user the code wherebinding.pryis located as soon as the code hits this debugger, whilebinding.irbdoesn't output anything to the user when the code hits this debugger (even if we callwhereamisometimes it doesn't output anything (😱), which is very confusing in terms of usability).2. What are the values ?!
In addition, there are bugs in
binding.irbrelated to not outputting the value of a variable when we call it! We can check it by looking at the above pictures and noticing the a variable value was not shown to the user here:On the other hand,
binding.prydoesn't have this bug and always output the value of a variable when we call it and press enter.Error-Proneness:
binding.irbappears to be more error-prone because thewhereamicommand doesn't show any context, making it difficult to understand where the debugger is paused. In contrast,binding.prysuccessfully displays the context, showing the exact location in the code where execution is paused. This indicates thatbinding.pryis generally more reliable for navigating the code and understanding the current execution state.Intuitive Interface:
binding.pryhas a more intuitive interface compared tobinding.irb. It provides commands likewhereamito show the current location in the code and has features such as syntax highlighting, code navigation, and history tracking.binding.pryoffers more advanced debugging tools out-of-the-box, making it easier for developers to inspect variables, control the flow, and understand the code's state.binding.irbis a basic interactive Ruby shell and lacks many of the helpful debugging features present inbinding.pry, making it less user-friendly for debugging complex issues.Therefore,
binding.pryis generally more stable and user-friendly thanbinding.irbfor debugging in Ruby.As a last note... Is there a way to fix all of these bugs in
binding.irb? In case not, I would recommend to keep usingbinding.pryfor the debugging process to avoid headaches.