Byebug đ
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
- 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.