I was trying to explain to my friend what a gem was in Ruby and I realized that while I understood what a gem was, I wasn’t great at teaching it! So this blog is for my friend and for anyone who “gets” what a gem is but is a little shaky on the specifics.
Ruby gems seem like magic at first! But they’re really just open-source libraries or plug-ins. A gem is a package of pre-written code you can download and install to fill a specific need. Using a gem allows a programmer to use the code within the gem in their own program, without explicitly inserting that code.
Gems can be used to extend or modify functionality in Ruby applications. Commonly they’re used to distribute reusable functionality that is shared with other Rubyists for use in their applications and libraries. Gems can help automate tasks and speed up your work.
Here are some examples of gems you may have already encountered and their functionality:
- Bundler: Provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. Bundler exists to solve the issue of gem version dependency.
- TTY-Toolkit: Is a gem that automates and simplifies the process of building a Command Line Application
- Rspec: Which we’ve used to run tests on our applications is a gem that supports Behavior Driven Development for Ruby.
- Rake: Rake supports rule patterns to synthesize implicit tasks
- Rails: Rails is also gem! Rails provides the fullstack framework that allows Ruby to be transformed into web applications
You can explore different popular gems at https://rubygems.org/releases/popular
RubyGems is the hidden hero here! Thanks to them, we have a rich ecosystem of helpful libraries just one gem install away.
Part of the magic of Gems is that we can all use them. RubyGems makes that possible! RubyGems and Bundler streamlined the process of sharing projects, if someone were to download your application all they would have to do is run bundle install and they would have access to all the necessary gems installed.
RubyGems became a part of the Ruby framework in 2004, folded into the standard Ruby distribution with Ruby 1.9.