Introduction to RubyGems
In this lesson, we are going to talk about an exciting and important topic called RubyGems. Gems are modules and classes that provide a ton of functionality, so they may even seem like magic. Essentially, these gems are nothing but Ruby code files that perform a certain task for you.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this lesson, we are going to talk about an exciting and important topic called RubyGems. Gems are modules and classes that provide additional functionality to an application. Some gems provide so many features that individuals new to development may even think of them like some kind of programming magic. However, essentially gems are nothing more than Ruby code files that perform certain tasks.

To give you an idea of how gems are used I'm going to open the Gemfile in a Rails project.

source 'https://rubygems.org'

gem 'rails', '~> 5.0', '>= 5.0.0.1'
gem 'pg', '~> 0.15'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'byebug'
  gem 'rspec-rails', '~> 3.0'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'factory_girl_rails', '~> 4.7'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

gem 'devise', '~> 4.2'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem "gritter", "1.2.0"
gem 'administrate', github: 'greetpoint/administrate', branch: 'rails5'
gem 'bourbon'
gem 'pundit', '~> 1.1'
gem 'puma', '~> 3.4'
gem 'twilio-ruby', '~> 4.11', '>= 4.11.1'
gem 'dotenv-rails', :groups => [:development, :test]
gem 'kaminari', '~> 0.17.0'
gem 'rails_12factor'
gem 'honeybadger', '~> 2.0'
gem 'newrelic_rpm', '~> 3.15', '>= 3.15.0.314'

Each of these gems contain a set of modules that allow programs to use them and not have to write every feature in an application from scratch. Using gems can save you quite a bit of time and effort so that you don't have to reinvent the wheel every time. There are thousands of gems available for you, and I recommend that you go to RubyGems.org to look at the full directory.

Below I walk through a few of the features that the gems from the code in this guide provides:

  • rspec provides a full automated BDD test framework for applications.
  • devise allows you to create a full authentication feature.
  • kaminari enables you to implement pagination anywhere it's needed in an application.
  • pundit gives developers the ability to build a full permission structure to ensure users follow the correct authorization rules.

I hope it gives you an idea of the power of RubyGems and how they can practically be used in a real world application.