Pry

Brian Sahota
4 min readOct 22, 2020

--

I really wanted to write a witty title for this. I really did. I thought of Pry Baby, or even Boys don’t Pry. But neither works here. Pry has been so good to me during my first Mod at Flatiron School, and I wanted to write a love letter to this beautiful gem.

Me

I failed my first coding challenge. It really sucked. I wanted to tell everyone that I was a bad test taker. And I did. It seemed like a good enough reason and everyone else that had failed was saying it as well. But it wasn’t the truth. I didn’t quite understand a few things. I really took some time to think about how I was going to approach the retake. And then I remembered some great advice I was given from students who had already gone through the first mod.

Get amazing at Pry.

And so I did.

Ok but what is Pry?

First we should see what a REPL is. REPL stands for Read, Evaluate, Print, Loop. Cool but what does that mean? It’s basically an interactive programming environment that takes a user’s input, evaluates (judges) it, and returns the results to the user. Ruby installs with its own REPL, which is called IRB. Every time you type irb into your terminal, you're entering into a REPL. But that’s like using Apple maps on your Iphone. No one uses Apple maps. We all use Google maps. Well Pry is like Google maps!

Me in class

Here’s what IRB looks like:

Every time we want to test our code we have to copy and paste it into IRB. What if I made a grammatical mistake? Or what if I needed to test other classes? I would also have to give variables a value so that I can test out the methods.Thats too much work, and as coders we are inherently lazy (allegedly). Pry literally injects a REPL into your program, that’s what she said, and with any gem, its pretty easy to install. Just type “gem install pry” in your terminal, you are the proud owner of one of the most helpful gems on the planet.

First we need to require ‘pry’ at the top of our file. Then we can place a ‘binding.pry’ anywhere in our file. Inserting a ‘binding.pry’ into your code will freeze your program at the point of its insertion. When the program hits pry, the program will open a REPL and we get a chance to pry into our code and see what is happening. Fun!

The hardest concept for me to grasp was ‘self’. I couldn’t understand it. What is self? Who is self? Is it you? Is it me? Is it my mom? Why is this so hard? It just felt like oh great i’ll never get this. But as I was getting better with Pry, ‘self’ slowly came into focus. We have a class method here called ‘self.all’. The first time I saw this I said, what all of my-self? And yeah kind of. This class method is trying to show us a list(array) of all Restaurants in that class. Whenever you want to test a class method, you should always use ‘name_of_class.all’. In this case we use Restaurant.all. Restaurant is self! Mind blown!

There are many other examples but my vocabulary is short and this is due in a few minutes. I honestly didn’t think I would get to this point in school. I thought I would have to retake Mod1 again. (tbd) This is my first blog post and it can only get better from here heh. I really owe a lot to Pry. It really bridged the gap in my knowledge.

So here are some more helpful hints from me to you:

  1. Master Pry.
  2. Make friends. Holy wow what a difference your classmates make.
  3. 3. Identify your weaknesses and face them head on. I know what it means to be comfortable. You need to leave that comfort zone and really tackle subjects that trouble you. It’s like learning Wonderwall on the guitar. Now you’re just playing Wonderwall every chance you get because you’re good at it. Stop playing Wonderwall and learn Stairway to Heaven.
  4. Enumerables- These can always be searched at any point in time but be focused on (.find, .map, .select,.collect,.filter, etc.) Just know these okay?
  5. Object Relationships
  6. Read the README, READ THE README, READ THE README!!! When starting your coding challenge, read every word carefully. You will see that most answers are hidden in the instructions.
  7. Don’t forget….everything’s gonna be alright

--

--