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
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`
# Show 41 lines within the context
# @ 20
# whereami 20

#   ?                  Alias for `show-doc`

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

#---------- 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?
# move up and down the call-stack (with up and down)
# display the callstack (with show-stack)


#---------- 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!

#---------- 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 /

#---------- break

break SomeClass#run            Break at the start of `SomeClass#run`.
break Foo#bar if baz?          Break at `Foo#bar` only if `baz?`.
break app/models/user.rb:15    Break at line 15 in user.rb.
break 14                       Break at line 14 in the current file.

break --condition 4 x > 2      Change condition on breakpoint #4 to 'x > 2'.
break --condition 3            Remove the condition on breakpoint #3.

break --delete 5               Delete breakpoint #5.
break --disable-all            Disable all breakpoints.

break                          List all breakpoints. (Same as `breakpoints`)
break --show 2                 Show details about breakpoint #2.