wiki (documentation and many of tutorials)
The gem is called pry
. If pry-rails
is also installed, pry will replace irb
in rails console. It will also add some commands such as show-models
or show-routes
. More info on pry-rails here.
binding.pry
will add a breakpoint in the code.
exit
will resume the execution. You can interrupt the execution and leave it with !!!
.
help
is available by its own or with another command.
ls
: It will show all methods, variables and constants available to pry. You can scope the search by adding an object. i.e.ls User
will list class/instance methods, variables, constants, etc. availables to the class.ls
has a lot of options in case you need to be more specific:
> ls # All
> ls -m # Methods
> ls -M # Instance methods
> ls -g # Globals
> ls -l # Local vars
> ls -c # Constants
> ls -i # Instance vars
> ls -G xx # Grey by regex
-
cd
: Change the current execution context to another object. i.e., beinguser
an instance ofUser
, you may usecd user
to be under the user scope. After that you can directly accessuser
methods and variables without the need to prependuser.
to everything. This is handy for debugging, when you find that the breakpoint is not where the bug is apparently ocurring and you need to move to another context to, for instance, override methods or variables. You can usercd ..
,cd -
orexit
to go back. -
show-source
: Show the source where the current breakpoint is. You can also pass another method/class. i.e.show-source User#full_name
. -
edit
: It will open the last command on the editor defined by $EDITOR. After saving and closing it will run it in pry. -
hist
: list the previous commands. You can also replay a range of last commands. More info withhelp hist
Pry will store the last exception in _ex_
. fun fact: you can use wtf?
to see the backtrace. The more exclamation and interrogation you add, the longer the backtrace (you can access all of it with _ex_.backtrace
; arguably more useful but less fun). More info about exceptions