Creating my first gem
The following is a guest post by Scott Luptowski and originally appeared on his blog. Scott is currently in the Ruby-003 class at The Flatiron School. You can follow him on Twitter here. A few weeks ago, I built a Ruby script to find the current standings of the English Premier League and display them in the terminal. […]
Reading Time 1 min
A few weeks ago, I built a Ruby script to find the current standings of the English Premier League and display them in the terminal. I decided to turn my standalone script into a gem called Standings, and the process was both easier and harder than I imagined.
Gems are built using a file called a .gemspec, which contains a list of metadata about your gem. It includes things like the version number, author’s name, and a list of runtime depencies (gems which will automatically download if you do not already have them).
Before I began the gem process, I assumed that the hardest part would be allowing computers to run the gem by typing its name directly from the command line, rather than inside of a pry session. It turns out that this was one of the easiest parts.
It turns out that what you’re doing here is adding information about the gem to your system’s PATH, which lets you call it from bash. Everything made more sense once I understood that.
Another issue I had was with properly requiring the correct files inside my actual gem. In a worrying turn of events, my computer read my code properly, while a classmate’s gem installation process did not work. My problem was in code which required all necessary files: some file invoked classes which were not yet defined, leaving Ruby very confused. I rearranged the
require_relative statements and it worked fine, but I’m still not sure what caused the error on one computer and not the other.
When it came to actual deployment, pushing the gem was painless. I created an account on Rubygems.org and typed
gem push standings from my terminal. In the future I’d like to add error handling, better notifications, and more documentation. I’d also like to include more soccer leagues via implementation of command line arguments.
Overall this was a great experience and I can’t wait to continue to play with the gem.
Posted by Flatiron School / October 22, 2013
Learn to Code Python: Free Lesson for Beginners
Sabrina Hernandez: From Dental Tech to UX / UI Product Designer
After 7 years as a dental tech, Sabrina Hernandez was ready for a change. She enrolled in Flatiron School and has since pivoted into a career in UX / UI Product Design.