All notes
Pry

Installation

richonRails.com.

Add in Gemfile:


gem 'pry-rails', group: [:development, :test]

Or



gem install pry

# Launch directly
pry
# Or include pry in your script
require 'pry'
binding.pry

Usage in debugging

Add a line:


binding.pry

Shortcuts

Stepping through code often? Add the following shortcuts to ~/.pryrc:

github: pry-rc.


Pry.config.commands.alias_command 'c', 'continue'
Pry.config.commands.alias_command 's', 'step'
Pry.config.commands.alias_command 'n', 'next'
Pry.config.commands.alias_command 'f', 'finish'

# Other shortcuts matching to byebug:
# l=    @
# backtrace   wtf

Commands



#---------- Help

help alias

# Aliases

#   !!!                Alias for `exit-program`
#   [email protected]                Alias for `exit-all`
#   quit               Alias for `exit`
#   quit-program       Alias for `exit-program`

#   $                  Alias for `show-source`
#   show-method        Alias for `show-source`
#   reload-method      Alias for `reload-code`

#   (?-mix:whereami[!?]+) Alias for `whereami`
#   @                  Alias for `whereami`

#   ?                  Alias for `show-doc`

#   clipit             Alias for `gist --clip`
#   file-mode          Alias for `shell-mode`
#   history            Alias for `hist`


#---------- Inspection

# Examine the headers of the response
response.headers

# Look at the instance variable @categories
assigns(:categories)

#---------- Exit

# Exit pry
exit-all
# You can also exit completely out of Ruby
exit!

#---------- cd, show_method

# changed scope to the category model
cd Category
# find the ordered method
ls --m --grep ordered
# Category.methods: ordered
# show-method
show-method ordered

# List the nested modules
nesting
# Jump to the uppermost module
jump-to 0

# recent stacktrace
wtf?

#---------- shell-mode

shell-mode

# From there you can run shell commands by prefixing the command with a ., for example:
.ls
.cat config.ru

#---------- show

show-models
show-model User

show-routes
find-route CategoriesController
recognize-path /

#---------- help
help