Building a CLI Gem — or how I learned to stop worrying and love binding.pry

Ohletamyleta
3 min readJan 14, 2021
Someone bring me coffee and tell me I know what I’m doing, please…

I came into Flatiron’s software engineering program from a decidedly non-technical background (chef with a theatre habit). I’d always found learning new skills something I excelled at. So imagine my surprise when I got to start constructing methods for my web scraper (top 50 pinball games of all time), and got really stuck. I was able to scrape the first level, game titles, and return them in order as a list:

I know it says Top 100, funny story that…

Originally, I had planned to scrape a different site, which had the top 100 games, so it should have been twice as fun, yes? No. Complex html code, and multiple entries in each piece of code, made getting a clean scrape impossible, at least for my beginner skills. I do plan to come back to that one though, I hate to walk away from a good challenge!

Now that I had a base to work from, I set my sights on finding a second layer of information that I could provide for the user to request. Initially I wanted to use the descriptions that were provided on the entries, but I couldn’t get the text blocks to sort properly, and I was on a deadline. So I turned my sights on the url links (which also contains the description text, conveniently enough!). But how to make sure I can scrape the data successfully?

I knew pry existed. People in my cohort had been talking about using it, but I had no idea exactly how it worked. Here is the important lesson I learned, part one: the only stupid question is the one that goes unasked. I didn’t want to look unprepared or behind, so I let my pride keep me from asking for clarification. I know I wasted a ton of time trying to modify my code without having a solid idea where the breakdown was. For instance, would the selectors I found for my url return the value I thought they would? well, I plugged the css value into my already working method, and…

I did it!

Pry is an incredibly valuable tool — and it is nothing to be afraid of. It’s rapidly becoming one of the most used lines of code I have learned so far. I highly recommend this article https://dev.to/elimerrell/debugging-with-pry-a-beginners-guide-3p99 for a terrific place to start.

Onward to finishing methods — with frequent use of the pry gem — and ever forward!

--

--

Ohletamyleta

Software engineering grad, theatre geek, master punster.