DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for   ~~~~~ BINDING.PRY ~~~~~
DanTheMan114
DanTheMan114

Posted on • Updated on

~~~~~ BINDING.PRY ~~~~~

Hello World! My journey of learning the ins and out of Ruby, (one of the coolest programming languages) was difficult until I was introduced to a build in class 'binding.pry'. I would find myself stuck in middle of a lab trying to go without using binding.pry. I thought I would be good 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 could save you 10 to 15 less headaches. BA DUM tssssss!!

Alt Text

~~~~~~~~~~~~~~~ General Setup and Info ~~~~~~~~~~~~~~~~

~ 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.

~~~~~~~~~~~~~~~~~ TIPS WHILE IN PRY ~~~~~~~~~~~~~~~

Alt Text

  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.

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

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

Alt Text

Alt Text

Alt Text

Alt Text

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

Remember pry is your friend when in trouble and when you are just not sure about your ruby code. If you made it this far thank you it was fun creating this quick crash course on explaining pry and how important it is to have while writing ruby. Happy prying, and cruising through ruby.

Alt Text

Top comments (0)

🌚 Life is too short to browse without dark mode