open-uri, a part of the standard Ruby distribution, makes opening and reading from a URI easy. With it, developers use familiar methods like open for performing I/O with URI’s.
require 'open-uri'
open("http://www.ruby-lang.org/") {|f|
f.each_line {|line| p line}
}
Contrast Net::HTTP which uses numerous methods to achieve the same effect.
require 'net/http'
url = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
puts res.body
An addon, SuperIO, adds more flexiblity in attempting to DTRT.