Pry

Learn the usage of Pry and how we can add Pry gems to our Gemfile.

Symbolic debuggers

Author’s note: Once upon a time, I was fans of development environments that had big fancy symbolic debuggers that let us set breakpoints and watch variables and step through the code. I was young and programming in Java, a language that had large integrated development environments.

When I started using TDD, I largely stopped using debuggers. Having small, focused tests eliminates most of the need to walk through code in a step debugger. That said, it’s sometimes nice to be able to stop a test in progress and peer inside the Ruby virtual machine to see what’s going on.

Enter Pry.

Pry

Pry is technically a Ruby console. In other words, it’s a souped-up replacement for irb, but with some add-on gems. It makes an excellent debugger. We can even coax it to reload code changes and rerun specs from inside Pry, which is as close as we can get in Ruby to programming inside a Smalltalk image.

Pry improves on irb in many ways. It offers a much more powerful examination of live Ruby objects. It also has some niceties that make it easier to enter code in the console.

Installing Pry

Let’s load Pry and a couple of extras by including them in the :development, :test group of the Gemfile:

Get hands-on with 1200+ tech skills courses.