Introducing Pry for Ruby

Introducing Pry

Pry is a Ruby gem and an interactive REPL (Read, Evaluate, Print Loop). A REPL is a programming environment that takes user input, evaluates it and outputs the result to the user. Other commonly used REPLs like IRB require you to enter a whole new environment each time. Once in IRB you’ll have to re-type or copy and paste the code that you’re looking to work with. Once you terminate your session, any variables, methods, or solutions you’ve come up with will disappear.

Enabling Pry

Pry can be easily installed, just by opening your terminal, navigating to the top of your directory using “cd~” and entering “ $gem install pry ” into the command line.

Debugging with Pry

Experimenting with Pry

Wrapping Up — The Power of Pry

As we’ve just seen here, provides us a valuable playground to debug our code, test our assumptions, and even write new code without relying too heavily on guesswork. Simply using “puts” to test code may work with simpler methods and data structures, but once things get complex, we’ll need to gain more insight into what exactly is going on. If we don’t get this insight, we’re likely to waste time blindly writing code. Think about all the things you could be doing with that extra time!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store