Debugging with Pry.
Learn what it is and how to use it.
Debugging your code can be a daunting, and sometimes debilitating, task if you’re ill-equipped. Today, I would like to share with you a great tool to use for debugging. You’re welcome.
Pry is a REPL. REPL stands for Read, Evaluate, Print, Loop. A REPL is an interactive programming environment. It is a tool that takes a user’s input, evaluates it, and returns a result.
Using Pry, the code we’re running pauses its execution and we enter into the Pry REPL. In it, we can manipulate data in various ways. So, how does it work?
In the file that you want to work in, you must require Pry, like so:
require 'pry'
In order to have access to Pry, it must be added to the Gemfile or installed locally. Visit RubyGems for Pry or other Ruby tools.
We added Pry to our Gemfile, we ran bundle install or gem install pry in our terminal, now what?
Let’s take a look at how we can call pry inside a method. Take a look at this example:
![]()
Inside a method, to initiate Pry, we must use “binding.pry”. This will pause the execution of our program and enter the Pry REPL. From there, we can manipulate the data in whichever way makes sense for us.
Using Pry, the code we’re running pauses its execution and we enter into the Pry REPL. In it, we can manipulate data in various ways. So, how does it work?
In the file that you want to work in, you must require Pry, like so:
require 'pry'
In order to have access to Pry, it must be added to the Gemfile or installed locally. Visit RubyGems for Pry or other Ruby tools.
We added Pry to our Gemfile, we ran bundle install or gem install pry in our terminal, now what?
Let’s take a look at how we can call pry inside a method. Take a look at this example:

Inside a method, to initiate Pry, we must use “binding.pry”. This will pause the execution of our program and enter the Pry REPL. From there, we can manipulate the data in whichever way makes sense for us.

Thanks for stopping by 🙃️, BYE!