Aaron Patterson calls himself a “puts debuggerer”. His article lists useful techniques for debugging ruby code using
- I know where I am but not how I got here:
puts callerwill print the call stack.
- I’m calling a method, but I don’t know where it goes:
p method(:render).source_locationwill show you where the method
- I’m calling super but I don’t know where that goes:
p method(:render).super_method.source_locationwill show you where method
render’s super is defined.
- An object is being mutated, but I don’t know where:
#freezethe object to trigger an exception (with backtrace) when it gets mutated.
- I have a deadlock, but I don’t know where: Inside the thread call
p t; puts t.backtraceto get insight.
And then there is always the
byebug gem with
step, etc. when puts is not powerful enough.