Created
May 4, 2015 20:42
-
-
Save laurenachoo/7718d5706c866fc9371a to your computer and use it in GitHub Desktop.
File I/O Exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
url = "http://ruby.bastardsbook.com/files/fundamentals/hamlet.txt" | |
local_fname = "hamlet.txt" | |
File.open(local_fname, "w") {|file| file.write(open(url).read)} | |
File.open(local_fname, "r") do |file| | |
file.readlines.each_with_index do |line, idx| | |
puts line if idx % 42 == 41 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rest-client' | |
wiki_url = "http://en.wikipedia.org/" | |
wiki_local_filename = "wiki-page.html" | |
File.open(wiki_local_filename, "w") do |file| | |
file.write(RestClient.get(wiki_url)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment