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.
1
Stdlib Ships With Ruby
JSON, Date, Set, CSV, Net::HTTP — no install needed, just require them.
2
require Loads Once
require "json" loads a library the first time; later requires of it are skipped.
3
Gems Are Packages
gem install rails downloads a versioned package from RubyGems.org.
4
Bundler Pins Versions
A Gemfile plus Bundler locks the exact gem versions a project depends on.
Batteries included, batteries downloadable
Stdlib Ships With Ruby1JSON, Date, Set, CSV, Net::HTTP — no install needed, just require them.
require Loads Once2require "json" loads a library the first time; later requires of it are skipped.
Gems Are Packages3gem install rails downloads a versioned package from RubyGems.org.
Bundler Pins Versions4A Gemfile plus Bundler locks the exact gem versions a project depends on.
4 building blocks make up Batteries included, batteries downloadable
How it works
From require to running code
Press Run and follow require "json" from request to usable API.
Watch it run
Three stdlib friends in one script
JSON turns text into Hashes, Set squashes duplicates, and Date does calendar math.
stdlib.rb
1require"json"
2require"set"
3
4data = JSON.parse('{"name": "Ada", "age": 36}')
5puts data["name"]
6
7nums = Set[3,1,3,2]
8puts nums.length
9
10require"date"
11d = Date.new(2024,1,15)
12puts d +20
main
require "json" loads the JSON library from the standard library.
Memory
no variables yet — press play
Console
output appears as the program runs…
Step 1/9
Practice
Match the library landscape
Click a term, then click its description to lock the pair.
6 conceptsTap a card to expand
?require "json"drops into place
?gem install railsdrops into place
?JSON.parsedrops into place
?Setdrops into place
?Datedrops into place
?Bundlerdrops into place
Challenge
Predict the output
A set that dedupes and a date that rolls over the new year.
libs.rb
1require"set"
2
3letters = Set["a","b","a","c"]
4puts letters.length
5
6require"date"
7d = Date.new(2025,12,25)
8puts d +7
Your predicted output — one line per console line
Hint: Sets drop duplicates, so only a, b and c remain. Date arithmetic rolls over the year: December 25 plus 7 days lands on January 1 of the next year.
Recap
Key takeaways
Key takeaways5 takeaways
01
The standard library ships with Ruby: JSON, Date, Set, CSV and more.
02
require loads a library once; Ruby tracks what is already loaded.
03
Gems are installable, versioned packages from RubyGems.org.
04
A Gemfile plus Bundler locks the exact versions a project needs.
05
Reach for stdlib before writing your own parser, set or date math.