Do you use debugging tools when studying Rails? A debug tool is a tool that supports the debugging work that is inherent in programming. Step execution is to execute a program line by line and check the operation while looking at the contents of the variables declared at that time. Can be done.
Let's introduce byebug used for Rails development.
First of all, if you install the byebug gem and put a method called "byebug" in the code you want to debug, it will stop when the program passes there, debug mode will start, and you can freely type commands interactively. You can execute and check the value of the variable.
Install on Gemfaile
Just add. (If you have rails installed, it is installed by default)
I will install the gem with.
To start byebug, write a method called byebug where you want to debug. (This place is an example.)
This time I will insert byebug in the static_pages / home page part.
After inserting byebug, try hitting the method.
In this way, the process will stop and the input prompt will appear. If you type next and press Enter
Moved to the next line. Now if you type to look up the help method and press Enter
You can check the contents of help. (You can also see the contents of the variables) In the actual debugging work, try executing the variable values and methods in this way to check if they are working as expected.
next Go one line forward continue Go to the next breakpoint Step inside the step method list View source code up View above the source code down View below the source code
If there are other commands you want to use, enter help and it will be displayed, so please check it ♪
Once you remember this far, I think the quickest way to get used to it is to actually write it.
I introduced byebug, but how was it? Byebug also allows you to see the types of each variable, so you can see the details of programming that tend to be black-boxed, speeding up development and two birds with one stone.
I think it's a very useful tool once you get used to it, so please try it ♪
Since I am a fledgling engineer, I think there are some mistakes and points that are difficult to understand. In that case, if you can add comments etc., it will lead to future growth, so please do not hesitate to contact us. If you press [LGTM], you will be happy to jump. Even Twitte is muttering, so please come and visit us if you like ♪