Skip to content

Instantly share code, notes, and snippets.

@cayblood
Forked from jimweirich/url_fetcher.rb
Created February 9, 2012 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cayblood/1779082 to your computer and use it in GitHub Desktop.
Save cayblood/1779082 to your computer and use it in GitHub Desktop.
Vital Ruby Advanced Lab 1
#!/usr/bin/env ruby
require 'open-uri'
class UrlFetcher
def self.fetch(url)
returnval = nil
begin
open(url) {|stream| returnval = stream.read}
rescue
end
returnval
end
end
if __FILE__ == $0
body = UrlFetcher.fetch(ARGV.first)
if body
puts body
else
puts "Error opening #{ARGV.first}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment