liveBook · Manning

Standard library

As explained in The Well-Grounded Rubyist, Fourth Edition

The standard library is the collection of libraries distributed with Ruby to provide commonly needed programming functionality.

Ruby’s standard library is a broad collection of extensions distributed with Ruby. It supplies reusable facilities for tasks such as URI handling, file manipulation, temporary files, databases, networking, specialized mathematics, and XML processing. section 1.2.1 section 1.3

Use require to load a standard-library feature at runtime. After loading, the feature can provide new classes and methods; require works with Ruby files and compiled extensions alike. section 1.3.3 section 1.2.2

Common standard-library facilities include:

Loading URI support

Before loading the feature, URI.parse raises an uninitialized-constant error. After require "uri", URI.parse("https://example.com/foo?bar=baz") returns a parsed HTTPS URI. section 1.3.3

>> uri = URI.parse("https://example.com/foo?bar=baz") 1
(irb):1:in '<main>': uninitialized constant URI (NameError)
from <internal:kernel>:168:in 'Kernel#loop' 
from /Users/jleo3/.gem/ruby/4.0.1/gems/irb-1.16.0/exe/irb:9:
➥in '<top (required)>' 
from /Users/jleo3/.gem/ruby/4.0.1/bin/irb:25:in 'Kernel#load' 
from /Users/jleo3/.gem/ruby/4.0.1/bin/irb:25:in '' 
from /Users/jleo3/.rubies/ruby-4.0.1/lib/ruby/4.0.0/rubygems.rb:303:
➥ in 'Gem.activate_and_load_bin_path'
from /Users/jleo3/.rubies/ruby-4.0.1/bin/irb:25:in '<main>'
>> require "uri"                  2
=> true 
>> uri = URI.parse("https://example.com/foo?bar=baz") 
=> #<URI::HTTPS https://example.com/foo?bar=baz> 

Inspect the IRB interaction showing the missing constant, the require call, and the resulting URI object. section 1.3.3

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains library locations, Ruby and C implementations, and require usage, while stopping short of exhaustive API reference.
Examples
Uses URI.parse, FileUtils, Pathname, StringIO, open-uri, rubylibdir, and architecture-specific extension files.
What it assumes
Assumes basic Ruby execution and introduces library discovery, runtime loading, and the distinction between Ruby and compiled extensions.
What you can do after
Apply it via require to load standard-library features and use the classes and methods they provide.
How it connects
Connects standard libraries with require, load, Ruby extensions, C extensions, URI handling, and file and I/O operations.

Also explained in

Compare how 7 books explain standard library →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.