Pry like a gentleman/lady!
IRB is designed as a REPL.
Pry is desinged as a...
..REPL..
..debugger..
and packs a whole lot of other useful stuff.
Features
-
Plugins
-
Context switching
-
Buffer editing
-
Documentation display
-
Medium for shell commands
-
Gem interaction
-
Friendly aliases
Plugins
pry-byebug: debugger
pry-theme: colorizes Pry
pry-doc: provides documentation
pry-globs: documents global variables
pry-rails: replaces IRB in Rails console
Context switching
ls - shows which methods, constants and variables are in the current context.
-
-m - show public methods defined on the object
-
-p - show public, protected and private methods
-
-g - show global variables + pry-globs
cd - move into new context
reset - reset the REPL to a clear state
whereami - describe the current location
nesting - show context nesting information
disable-pry - return from debugging mode
Buffer editing
show-input - show the contents of the input buffer for the current multi-line expression
amend-line - edit buffer content in a multi-line mode
edit - open a text editor. If FILE is not given it will edit buffer content. When a method/class/module is given, the code will open in text editor
Documentation display
show-doc / ri - show documentation for a method or a class
show-source - show the source of a method, class or a module
stat - show detailed method information
Medium for shell commands
cat - show part or a whole source file
prefix '.' - commands prefixed with a dot will be passed to the underlying shell
Gem interaction
gem-cd - move working directory into a gem's directory
gem-install - install and reload the gem cache
gem-list - list all gems
gem-open - open gem's directory in text editor
Aliases
!!! - exit program
$ - show source
? - show documentation
@ - whereami
show-method - show-source
Pry in Rails
-
pry-rails: in addition to initializing console with Pry, it provides show-routes and show-model(s) commands
-
pry-byebug: enables thorough debugging with step, next and continue commands. Easily dig into internals of Rails.
-
find-method: recursively search for a method within a Class/Module or the current namespace
Less known niceties
-
; - will supress the output of the evaluation
-
_ - will run the last evaluation
-
use Pry's help command! It includes plugin descriptions as well
-
customize your Pry experience in .pryrc
Resources
Pry like a gentleman/lady!
Pry
By Dario Daic
Pry
Pry blitz-talk
- 626