Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dportalesr/a585d4dc6c6d97ca1692acb366e7d02b to your computer and use it in GitHub Desktop.
Save dportalesr/a585d4dc6c6d97ca1692acb366e7d02b to your computer and use it in GitHub Desktop.
Pry cheatsheet

Pry Cheat Sheet

Youtube Tutorial 2013

Command Line

pry -r ./config/app_init_file.rb  —— Load your app into a pry session (look at the file loaded by config.ru)
pry -r ./config/environemtn.rb    —— Load your rails into a pry session

Debugger

help <command>  —— Display command options for pry command ls

ls              —— Show all of the available methods in the current scope
  ls --locals   —— Show all local variables available in the current scope
  ls <Object>   —— Show all of the available methods that can be called by an object

_               —— Last eval
? <Object>      —— Shows more information (doc) about an object, or method
_file_          —— Represent the last file Pry touched
wtf?            —— Print the stack trace, same as _ex_.backtrace
$               —— Show source, alias for `show-source`
edit <Object>   —— Open file in $EDITOR
<ctrl+r>        —— Search history
_out_           —— Array of all outputs values, also _in_
cd <Object>     —— Step into an object, change the value of self
cd ..           —— Take out of a level
binding.pry     —— Breakpoint
edit --ex       —— Edit the file where the last exception was thrown
.<Shell>        —— Runs the <Shell> command
whereami        —— Print the context where the debugger is stopped
whereami 20     —— Print the context 20 lines where the debugger is stopped
;               —— Would mute the return output by Ruby
play -l         —— Execute the line in the current debugging context

pry-nav

next      —— execute next line
step      —— step into next function call
continue  —— continue through stack

pry-rescue

rescue rspec        —— break on exception in rspec
rescue rails server —— break on exception in rails server
try-again           —— run last failing spec, reloads the file not the enviornment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment