Ruby Programming/Standard Library/OpenURI

From Wikibooks, open books for an open world
Jump to navigation Jump to search

OpenURI[edit | edit source]

OpenURI can be used to download a web page. Ex:

require 'open-uri'
   open("http://www.ruby-lang.org/") {|f|
     f.each_line {|line| p line}
   }

It appears to monkey patch the default "open" method for you, so that it is enhanced to take url's as well as its typical filenames etc.

See also Net::HTTP