Debugging in Ruby

Before I started doing Ruby I was doing mostly C#. This meant I did pretty much all my development in Visual Studio, giving me access to a very powerful debugger. Coming into the world of Ruby meant switching to Vim, which meant my editor started up in less than a second (instead of a few minutes), but it also meant I had to give up all the debugging power.

Not all is lost however – there are a few debugging tools to help you in this dynamic world. There is ruby-debug which is designed to allow you to see what goes on inside a Ruby program while it executes.

Another popular tool – which is the one I use on a daily basis – is Pry. It’s basically a repl (read-eval-print loop) and allows you to poke at variables while your application is running. It’s very rare that I need more than this in order to debug a Ruby program.

Pry also has some more advanced features allowing you to treat an object like a file system (you literally use commands like cd and ls to interrogate objects). While these are pretty neat I still find that I don’t really need powerful debugging tools. The most advanced thing I probably do on a daily basis is to view the methods an object has:

some_object.methods - Object.methods

Pry is packaged as a gem and is increadibly easy to use. It’s definitely a power tool in any Ruby developer’s arsenal.

Happy coding.