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:
- URI parses and handles uniform resource identifiers. section 1.2.1 section 1.3.3
- FileUtils provides utilities for manipulating files. section 1.2.1 section 12.5
- Pathname, StringIO, and open-uri support filesystem paths, string-backed I/O, and URI reading. section 12.5
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






