timhwang21.gitbook.io
  • Intro
  • Blog
    • 2023
    • 2022
    • 2021
    • 2020
    • 2019
  • CLI
    • Git
      • Bulk resolve merge conflicts
      • git rebase-onto
      • Patch from diff
    • Shell
      • Recipes
    • Vim
      • Batch editing
      • Buffers
      • <Ctrl-r>
      • External commands
      • :global
      • Help
      • Registers
      • Splits
    • Tools
  • Programming
    • React
      • Testing Styled Components
    • Typescript
      • curryRecord
      • Exhaustive conditionals with ADTs
      • newtype
      • OmitTypes
      • Safe JSON clone
      • Type inferrers
      • XOR type
    • Ruby
      • Pry
      • RSpec
    • Rails
      • Attributes
      • Cheap many to many
      • (Don't use) counter cache
    • Databases
      • Metrics
      • Testing indexes
  • Personal
    • Uses
    • Github
    • Medium
    • LinkedIn
    • Photography
Powered by GitBook
On this page
  • binding.pry in external code
  • Get filtered stack trace
  1. Programming
  2. Ruby

Pry

Pry tricks

binding.pry in external code

Simply monkey patch the method that you are interested in debugging:

def SomeGem::method
  require 'pry'
  binding.pry
  super
end

You can even do this automatically for a list of methods you are interested in:

[:foo, :bar, :baz].each do |cb|
  define_method cb do
    require 'pry'
    binding.pry
    super
  end
end

Get filtered stack trace

# at breakpoint
caller.select {|line| line.starts_with? '/your-app-dir' }
PreviousRubyNextRSpec

Last updated 3 years ago