Rails 7 replaced byebug with ruby/debug


As we know, debuggers are the main tools for programmers to debug the code easily. With the latest changes in Rails 7, byebug is replaced with ruby/debug.

Byebug has been helping Rails programmers debug their applications since 2014. We can refer to that PR here. Rails 7 comes with debug as its default debugger.

debug is Ruby’s new debugger and will be included in Ruby 3.1. It is planned to be a standard library of Ruby 3.1. Adding debug to Rails 7 will align Rails with Ruby.

Here is an example of debugging in both Byebug and Debug.

Debugging using byebug

  class TestController < ApplicationController
    def index
      name = "Sam"
      age = 23
      byebug
      place = "Boston"
    end
  end

  # Result

  [1, 8] in /Users/sam/test_app/app/controllers/test_controller.rb
    1: class TestController < ApplicationController
    2:   def index
    3:     name = "Sam"
    4:     age = 23
    5:     byebug
  => 6:    place = "Boston"
    7:   end
    8: end
  (byebug) name
  "Sam"

Debugging using Ruby Debug,

  class TestController < ApplicationController
    def index
      name = "Sam"
      age = 23
      binding.break
      place = "Boston"
    end
  end

  # Result

  [1, 8] in ~/test_app/app/controllers/test_controller.rb
      1| class TestController < ApplicationController
      2|    def index
      3|       name = "Sam"
      4|       age = 23
  =>   5|       binding.break
      6|       place = "Boston"
      7|    end
      9| end
  =>#0	TestController#index at ~/test_app/app/controllers/test_controller.rb:5
    #1	ActionController::BasicImplicitRender#send_action(method="index", args=[])
  (rdbg) name     # ruby
  "Sam"
  (rdbg) continue # command

For more details regarding commands and features of Ruby Debug, please check this out Ruby-Debug.