Pry – Part 2

More on using Pry.

Let’s play around with it a little using the Hello World gem (if you haven’t already installed it, use: gem install hello_world). Then, in pry:

Some useful commands:

1. ls:
ls shows you which methods, constants and variables are accessible to Pry. By
default it shows you the local variables defined in the current shell, and any
public methods or instance variables defined on the current object.

So we can list, class methods:

i.e. nothing.

Instance methods:

i.e. this method is available.

And this is the default, i.e.


2. cd
cd moves you into a new context (object or scope). As in UNIX shells use cd .. to go
back, cd / to return to Pry top-level and cd – to toggle between last two


and now:

So, we can invoke it like this:

However, if we’re only interested in the output value and not the return value then we can use a semi-colon:

More in Pry – Part 3.

Leave a Reply

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