Skip to content

What is Ruby? What are Gems, Gemfile, and Gemfile.lock? Why do I see "rb this" and ".rb that" everywhere in the Refuge Restrooms GitHub repo?

DeeDeeG edited this page Jun 11, 2018 · 6 revisions

Ruby is a programming language.

Does that mean I have to program? Do you have to write code to use ruby?

Not necessarily.

Ruby has a thriving community of programmers, some hobbyists, others seasoned professional developers, and they have cumulatively release hundreds, if not thousands of open-source projects written in Ruby.

If you want to make an app, or run a web server using ruby, there's a good chance that someone has done the heavy lifting for you already. Perhaps the most famous Ruby project of them all is Ruby on Rails ('Rails' for short), which is a web app framework that Refuge Restrooms uses to develop its web pages.

How do I get ruby software? How do I benefit from Ruby's "thriving community"?

It's all about the Gems! Just like Windows users install .exe's on their computer to get new programs, Ruby developers import Gems into their software project to get new features.

We have a Gem to interpret Sass (sass-rails) interpret CoffeeScript (coffee-rails) and interpret HAML (haml), a Gem to get emails from website users (mail_form), block spam (rakismet) and administrate over the site and database (activeadmin).

Just like on the Apple App Store, whatever you need, "There's an app a Gem for that!"

To see a list of Gems Refuge Restrooms uses, see Gemfile and Gemfile.lock.

What are [filename].rb files?

These are source code, written in the Ruby language. To learn more about how to read and write Ruby, see:

https://www.ruby-lang.org/en/documentation/ or https://ruby.github.io/TryRuby/

What's the deal with Gemfile, and Gemfile.lock

The Gemfile specifies what our basic requirements are in order to run the Refuge Restrooms web app.

The Gemfile.lock file additionally lists what Gems actually installed last time the Gemfile dependencies were asked to be installed. Usually Gemfile.lock is much longer than Gemfile, because the Gems listed in Gemfile are ones our developers have asked for explicitly, whereas those Gems may ask for other Gems that they depend on, which are then automatically installed in order to "satisfy" the dependencies.

There is a program called Bundler*, which installs every requirement from Gemfile.

Assuming we are running our server under Vagrant:

Vagrant up sets up our base machine (a virtual machine running Ubuntu 14.04), and runs a script named setup_vagrant.sh. Line #82 of the script instructs Bundler to install the Gems listed in Gemfile.

* fun fact: Bundler itself is installed as a Gem. gem install bundle at line #79 of the aforementioned setup_vagrant.sh.

Further Reading

For advanced understanding of the Gemfile, in order to read it and edit it, see the manual for Gemfiles: https://bundler.io/man/gemfile.5.html

(Or alternatively, this nicer, easier-to-read explanation in article form: https://tosbourn.com/what-is-the-gemfile/)