Search

My Top 5 Pry Features

Gregg Rothmeier

2 min read

Nov 8, 2012

My Top 5 Pry Features

Ruby ships with an Interactive Ruby Shell (IRB) that every Ruby developer has played around with at some point. It’s a great place to experiment with unfamiliar methods and running bits of code, but if you really want to dig into an object or do hardcore debugging, it can leave a lot to be desired.

Pry is a great IRB alternative that has a number of features that make it one of my must-have tools.

Pry has five features that make it great:

View the documentation or source for a method

You may often find yourself wondering about the difference between methods like #reject and #reject!, but you don’t feel that it warrants a full Google search. Pry provides a show-doc method that makes this painless:

If you’re working with your own code and want to take a quick look at the source, there’s also show-method:

Search your Pry history

Pry’s hist --grep makes it easy to search through your Pry history:

Edit and reload files

Rather than switch between Pry and your editor, you can use edit to open up a file for editing:

The only “gotcha” is that you need to make sure you specify your editor in a .pryrc file:

Additionally, the -t flag opens up a temp file, giving you a full editor to define a method, class or other ruby object, if you find doing it line-by-line in Pry to be too tedious.

Run shell commands

You can run shell commands by prepending the command with a ‘.’. This is great when you’re working on a gem and want to edit a file without leaving Pry:

Any command with a ‘.’ in front will be forwarded to the shell, so you could even commit your code from Pry.

Dive into objects

You can navigate around Ruby objects as if there were folders by using cd and ls:

ls is useful for when you forget the name of that variable you defined earlier, and cd can be useful for diving into objects.

Bonus!

This feature is available in IRb as well as Pry, but it’s something that I use very often:

These are just the highlights of Pry and some of the commands I use. You can find more information on the commands on the Pry wiki and by using the help command in Pry. If you’re looking for more help with debugging, make sure you check out Aubrey’s post on pry-remote.

These are my favorite Pry features—what are yours?

Zack Simon

Reviewer Big Nerd Ranch

Zack is an Experience Director on the Big Nerd Ranch design team and has worked on products for companies ranging from startups to Fortune 100s. Zack is passionate about customer experience strategy, helping designers grow in their career, and sharpening consulting and delivery practices.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News