Finding and Choosing Gems

ruby

One of the big challenges of being a developer is learning how to find the resources you need to add a particular feature. Which gem for pagination or debugging or user authentication, etc, etc, is the best for your project? Here’s some brief advice on that: Sites for Finding Ruby Gems to Use

  • RubyGems: The RubyGems site has a searchable database of gems with information on how popular they are, how recently updated they are, authors, etc.
  • Ruby Toolbox: This site has a lot more information about gems than RubyGems, and in my opinion the search results are much more well selected vs RubyGems. If the information is up to date, it is often easier to find what you need on Ruby Toolbox. However, it is, at present, not being updated very consistently, so the information can, at times, be outdated.
  • Railscasts: Ryan Bates chose topics at least in part by popular request, which means if you find a gem covered in a Railscast, chances are it was fairly widely known and used at the time the video was made.
  • LibGrader: This site is a relative newcomer to the field of gem searches, but as far as I’ve used it has had good search results and metrics for its listings.
  • Honorable mentions: searching on Google, GitHub, or “What gem should I use”-type questions on Stack Overflow

Selecting Which Ruby Gems to Use

There are a few important things to look for when choosing a gem to use out of a list of possible options. Say you want to find a pagination gem for a Rails application. You’ll probably run across will_paginate, kaminari, and a number of other, less-used ones. In choosing between them, here are some things you would consider:

  • What version of Ruby and/or Rails does it say it is compatible with? Some gems that were widely used for Rails 3 have never been updated to be Rails 4 compatible. If you’re using a Rails 4 app, be wary of Rails gems that don’t explicitly say they are compatible with Rails 4, especially if they DO say they are compatible with Rails 3. You can usually find this information on the README section of a gem’s GitHub page. Similarly, if a gem was written in Ruby 1.8 and you’re using Ruby version 2.2, it may no longer work as you expect.
  • When was it last updated? Check out the gem’s GitHub page (you can find links for these on RubyGems, Ruby Toolbox, and Railscast pages, or just Google it), and look at the date (”authored on Feb 12″, in the below image is the date of the most recent commit for that repo as shown on GitHub). A gem that has been updated in the last few months is a much better bet than one last updated two years ago.

the twitter-bootstrap-rails GitHub page show a commit with "authored on Feb 12" next to it

  • How popular is it? Both Ruby Toolbox and RubyGems have data on the number of times gems have been downloaded. Ruby Toolbox will generally have some more data on whether a gem has been trending up or down over time. They also have their own formula for judging the present-day popularity of a gem which will display when you compare gems in the same category (e.g. “pagination”) on their site. See image below for an example.

a search result for "pagination" on Ruby Toolbox showing popularity ratings for the WillPaginate, Kaminari, and Sorted gems