Pry – an IRB alternative and runtime developer console – Part 1

A brief guide to Pry:

1. Install
gem install pry pry-doc –no-ri –no-rdoc

pry-doc lets you browse core C source
Other flags: don’t bother installing the docs ‘cos it takes extra time

2. Features
Run pry

Useful commands:
a. help help

Note: pry offers command line completion.

b. show-doc
Show the documentation for a method or class. Tries instance methods first and
then methods by default.

e.g. if we create an object like this:
s = “pry”
then we can do:
show-doc s.each_line

From: string.c (C Method):
Owner: String
Visibility: public
Signature: each_line(*arg1)
Number of lines: 30


Note, show-doc is smart. Can even read ri syntax.
show-doc String#each_line
which gives the same documentation.

c. show-method
show-method s.each_line

shows each line of the implementation for String.

-l gives you line numbers.

d. Share your code
gist s.each_line
creates a gist and copies the URL to your clipboard.

More info here:
The screencast there is great although it’s for a slightly older version of pry.
E.g. autocomplete on gist-method doesn’t work because this method doesn’t exist any more. It’s just called gist now.

See also:

This post is getting rather long so the rest will be in Part 2.

Leave a Reply

Your email address will not be published. Required fields are marked *