Git Product home page Git Product logo

pry-byebug's Introduction

pry-byebug

Version Build Inline docs Gittip

Fast execution control in Pry

Adds step, next, finish and continue commands and breakpoints to Pry using byebug.

To use, invoke pry normally. No need to start your script or app differently. Execution will stop in the first statement after your binding.pry.

def some_method
  puts 'Hello World' # Run 'step' in the console to move here
end

binding.pry
some_method          # Execution will stop here.
puts 'Goodbye World' # Run 'next' in the console to move here.

Installation

Drop

gem 'pry-byebug'

in your Gemfile and run

bundle install

Make sure you include the gem globally or inside the :test group if you plan to use it to debug your tests!

Execution Commands

step: Step execution into the next line or method. Takes an optional numeric argument to step multiple times.

next: Step over to the next line within the same frame. Also takes an optional numeric argument to step multiple lines.

finish: Execute until current stack frame returns.

continue: Continue program execution and end the Pry session.

up: Moves the stack frame up. Takes an optional numeric argument to move multiple frames.

down: Moves the stack frame down. Takes an optional numeric argument to move multiple frames.

frame: Moves to a specific frame. Called without arguments will show the current frame.

Matching Byebug Behaviour

If you're coming from Byebug or from Pry-Byebug versions previous to 3.0, you may be lacking the 'n', 's', 'c' and 'f' aliases for the stepping commands. These aliases were removed by default because they usually conflict with scratch variable names. But it's very easy to reenable them if you still want them, just add the following shortcuts to your ~/.pryrc file:

if defined?(PryByebug)
  Pry.commands.alias_command 'c', 'continue'
  Pry.commands.alias_command 's', 'step'
  Pry.commands.alias_command 'n', 'next'
  Pry.commands.alias_command 'f', 'finish'
end

Also, you might find useful as well the repeat the last command by just hitting the Enter key (e.g., with step or next). To achieve that, add this to your ~/.pryrc file:

# Hit Enter to repeat last command
Pry::Commands.command /^$/, "repeat last command" do
  _pry_.run_command Pry.history.to_a.last
end

Breakpoints

You can set and adjust breakpoints directly from a Pry session using the following commands:

break: Set a new breakpoint from a line number in the current file, a file and line number, or a method. Pass an optional expression to create a conditional breakpoint. Edit existing breakpoints via various flags.

Examples:

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.

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

Type break --help from a Pry session to see all available options.

breakpoints: List all defined breakpoints. Pass -v or --verbose to see the source code around each breakpoint.

Caveats

Only supports MRI 2.0.0 or newer. For MRI 1.9.3 or older, use pry-debugger

Credits

  • Gopal Patel (@nixme), creator of pry-debugger, and everybody who contributed to it. pry-byebug is a fork of pry-debugger so it wouldn't exist as it is without those contributions.
  • John Mair (@banister), creator of pry.

Patches and bug reports are welcome.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.