Ruby Gems & How To Use Them. In my recent “what the hell is Ruby and…
By: Sarah Daniels
Tags: Flatiron School, Rubygems, Ruby on Rails, Ruby, Coding

In my recent “what the hell is Ruby and how do I use it” learning experience, I’ve been taught how to build something from bare bones. Writing out every minute detail — methods, variables, routes, files they go in — all of it. In a dizzying whirlwind of trying to comprehend and regurgitate these small details, I thought “holy crap, is this what it’s like to be a developer? This is insane amounts of work just to get tiny components working. I am totally incapable of this”. Right before I hit “sitting in the shower crying” rock bottom, I was introduced to Rails and many wonderful gems.

What are gems?

Gems are, on the surface, a little package of code that makes your developing life a pinch easier (read: fewer emotional breakdowns, more productivity). Gems are a library that provide the foundation for establishing certain functions — this library contains all the files and code to help you do that. Some of these functions include (but are not limited to) credit card processing, testing your code, and user authentication.

The best and worst thing about gems is they are open source. I can meander over to rubygems.org and download practically any gem I can think of. But with that, you might have to sift through some junk. At the time of this post, there are 151,973 gems available!

While there are some super helpful gems, there are a lot of garbage or out of date gems that don’t work and can be a headache to navigate. A simple but solid lesson I’ve learned — make sure you have the correct version of a gem. Better yet, make sure you have the right gem. Take a look at how many downloads it has. If there is a gem with four downloads and an eerily similar one with a million…. maybe go with the slightly more popular option.

How do I install a gem?

Rubygems.org makes installing gems a fairly painless process and breaks the steps down for you. First, search for the gem you’re looking for. The specific gem page should have something like this….

Copy and paste the first line into your gemfile and then run “gem install <gem name>” in your terminal. Bam, gem at your service.

If there are more steps outside of the simple “install”, the “documentation” page under “links” will most likely spell it all out for you. After a little tinkering, you’re able to process payments and have users log into your application and other seemingly in-depth stuff. Holy smokes. Something that once seemed so out of reach, someone else has already done for you. Next learning goal/major caveat: what the heck is going on in within this gem? That’s for another post.

What gems do I dig?

I haven’t utilized many as a fairly new bootcamp student, but these have proven to be solid options. Special thanks to Codica for breaking down what these gems do in a more succinct manner than I ever could.

“Byebug is a simple to use and feature-rich debugger for Ruby. This gem allows line-by-line fulfilling of code, pausing between tasks and executing code, changing the variables on the move.”

“RSpec suggests Behaviour Driven Development for Ruby. The gem provides standards for Ruby on Rails apps testing. It offers more readable DSL, as compared to TestUnit standard testing library. Beyond that, it easily integrates with many other gems that facilitate the testing process.”

“Capybara is an acceptance test framework for web applications. It flawlessly runs in tandem with RSpec. The gem is responsible for integrated tests that imitate users’ actions in a browser. It allows describing the authorization scenario in few lines (go on the homepage, enter a login and password, click the Log-in button), suggesting then various convenient methods for tests debugging.”

“Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.”

“Devise is a flexible authentication solution for Rails based on Warden. Devise helps build an identification system of any complexity level — from authentication via email and password to a referral system. In a nutshell, it has 10 modules, including: