Gems and Standard Library

Lesson 20 of 20

require, RubyGems and the standard library: JSON, Date and Set are one require away — never hand-roll what already exists.

The big picture

Batteries included, batteries downloadable

Ruby ships with a standard library of ready-made tools, and RubyGems.org holds thousands more — both plug in with a single require.

Stdlib Ships With Ruby

JSON, Date, Set, CSV, Net::HTTP — no install needed, just require them.

require Loads Once

require "json" loads a library the first time; later requires of it are skipped.

Gems Are Packages

gem install rails downloads a versioned package from RubyGems.org.

Bundler Pins Versions

A Gemfile plus Bundler locks the exact gem versions a project depends on.