Rails 7.0 replaces byebug with ruby/debug

Debugging information can help you understand what’s going on in your application. After Rails 5 and before Rails 7, the byebug gem was responsible for tracking the execution flow. It has been providing a way to view a complete backtrace of the code while working on the application. Rails 7 introduces debug as its default debugger.

debug comes from Ruby 3.1 standard library and will align Rails with Ruby. It also supports remote debugging natively, as well as recording and reply debugging. More about the gem can be found here.

One of the primary benefits is that it allows users to debug their applications more efficiently and effectively. Byebug was an excellent tool for debugging, but it wasn’t easy to use in some situations. For instance, if you had an application that required you to use breakpoints, you would have to restart your server whenever you wanted to rerun those breakpoints. This made it hard for you to test changes quickly and efficiently because every time you made a change or added a new feature, you would need to restart your server before testing again.

With ruby/debug, however, all breakpoints are automatically cleared when the application restarts, so there is no need for any additional steps or actions on your part unless desired otherwise (such as re-enable specific breakpoints).

Another benefit of this new tool is that it provides better error handling when debugging, making it more accessible than ever! One of the main issues with byebug was that it did not offer any error handling features when debugging, which meant that whenever there was an error during execution, then byebug would crash without giving any information about what went wrong or why.

debug can be called with binding.break method (aliases: binding.b, debugger)

class UsersController < ApplicationController
  def index
    name = "John"
    surname = "Smith"
    binding.break # Call to debugger
    place = "New York"

The new debugger is also contains methods like break, catch, backtrace, and outline.

In addition, Ruby/debug also allows for more flexibility in terms of what information is available during debugging sessions since it doesn’t require any other software.