DEV Community

Cover image for ~~~~~ DeBugging ~~~~~
DanTheMan114
DanTheMan114

Posted on

~~~~~ DeBugging ~~~~~

Hello World! My journey of learning the ins and out of Ruby and Ruby on Rails, (one of the coolest programming languages) was difficult until I was introduced to a build in class 'binding.pry', and 'byebug'. At times I would find myself stuck in middle of a lab trying to go without using binding.pry, or byebug. It seemed like a good idea to go without it, but it was only hurting me in the long run. I think of binding.pry this way; I can still drive my car around without insurance but should I, no its just not worth it. I think switching to binding.pry, and byebug could save you 10 to 15 less headaches. BA DUM tssssss!!

Alt Text

Before we get to the fun I would like to say these a just a few tools to help a brand new individual to programing. Binding.pry and byebug and Google will be your new friends along your programing journey. So follow the instructions, dont forget the tips, and google for help if you get lost.

~~~~~~~~~ General Setup and Info For Binding.Pry ~~~~~~~~~

~ Binding.pry is a built-in ruby class, whose objects can sum up the context of your current scope, variable, or methods, and direct them to the terminal for further dissection.

~ To use binding.pry, the user must require 'pry' at the top of all the code within the current class.Then below or in between their lines of code. Example below!

Alt Text

~ Binding.pry is used in ruby programming to debug code, and to find out what happening to a users code before the code is finally executed.

~ Do not forget binding.pry will stop your code in its tracks, during a run execute and bring the user right to the terminal.

~ The main use of this wonderful tool is to keep your mind on what is going on, in a specific/up to moment in your ruby code.

~~~~~~~~~~~ General Setup and Info For Byebug ~~~~~~~~~~~

~First things first when using byebug all you have to do it type 'byebug' with in th method you would like to go within.

~Before that make sure you have it installed with a simple

`gem 'byebug'

`
or if you start your rails project with rails new blahblah it should install it for you.

~Next you have to remember in order to hit the byebug you have to navigate through your rails application on the web with localhost:3000/balh.

~Then its will pop up in your terminal and you can play around with your instances and check if your out put is correct and what not.

~For example:

def your_method_name

byebug

end

~Once again to do an overview just make sure you have the gem installed and have fun, google if your friend if this does not help.

~~~~~~~~~~~~~~~~~ TIPS WHILE IN PRY/Console ~~~~~~~~~~~~~~

  1. If you are ever stuck with in pry and want out 'exit!' or '!!!' is the best way out.

  2. Another handy one is if you are returning a bunch of instances hit 'q' to quit and it will end while keeping you in pry.

  3. If the user is ever lost one could type self, or whereami to get current location within pry.

  4. A cool short cut to click anywhere on the terminal for mac is to hold down option and click, instead of deleting everything.

  5. Remember pry will always tell you when something is missing, including calling a method or class by the wrong name, and or misspellings it.

  6. When in pry type 'help' for a list of commands and explore more options of assistance, Im not saying you wont need google but this will help.

  7. When you need to reload your server you can type 'c' to continue. Also with the byebug 'q' to quit, just type exit. Im sure the '!!!' does not work with in the byebug just binding.

~~~~~~~~~~~~~~~~~~ Notice MEEE!!! ~~~~~~~~~~~~~~~~~

This is a section where I like to show and NOT tell via gif.

Alt Text

Alt Text

Alt Text

Alt Text

Alt Text

~~~~~~~~~~~~~~~~~~ Thank You ~~~~~~~~~~~~~~~~~~

Remember pry and byebug is your friend when in trouble and when you are just not sure about your ruby code, hit up google. If you made it this far, it was a short read but thank you it was fun creating this quick crash course on explaining some tools of debugging and how important it is to have while writing ruby. Happy coding, and cruising through ruby, and rails.

Alt Text

Top comments (0)