Byebug 👋

Kendall Stephens
2 min readNov 11, 2020

Wait! — before you throw your computer out the window because of yet another misspelled variable, try inspecting your code with byebug!

Byebug is a ruby gem that allows you to see what’s going on inside of your program while it’s running. It allows you to stop your programs execution and take a peek under the hood to see what your code is doing.

Ruby on Rails already includes this wonderful gem in their application. If you’re not using rails it’s easy to install by adding ‘require byebug’ in your gemfile and running bundle install(tip — be sure you include the gem globally or inside the :test group if you plan to use it to debug your tests! 😉).

Once you have your program setup with the byebug gem you are ready to get your bug investigation on! Simply type byebug below a line of code you’d like to inspect and run your program.

Byebug will then stop your program and show you exactly where it’s at so you can take a look!

Ok, so what to do now? Here are a few of my favorites commands to get you started! To see a complete list of the commands offered, simply type ‘help’ in your terminal while in your byebug session. To end your session type ‘end!’.

  • pp pretty prints variables
Had to provide a visual for this one, 😍
  • n runs one of more lines of code
  • s steps into blocks or methods one or more times
  • c runs until the program ends, hits a breakpoint or reaches a line
  • disp­ evaluates expressions every time the debugger stops

The vail has been lifted — thanks to the my new best friend, byebug :) I highly recommend utilizing this amazing gem to preserve your sanity and those around you.

--

--