Skip to content

Instantly share code, notes, and snippets.

@cody-code-wy
Last active May 30, 2016 19:29
Show Gist options
  • Save cody-code-wy/f07e825f9fbac34aee047105a17b8ea7 to your computer and use it in GitHub Desktop.
Save cody-code-wy/f07e825f9fbac34aee047105a17b8ea7 to your computer and use it in GitHub Desktop.
require 'open-uri'
hamlet = open("http://ruby.bastardsbook.com/files/fundamentals/hamlet.txt").read
open("hamlet.txt",'w') { |file| file.write(hamlet) }
hamlet = open("hamlet.txt",'r')
hamlet.readlines.each_with_index do |line,index|
puts line if index % 42 == 0
end
hamlet.close
file = File.open("f1.txt","w")
file.puts "Hello File"
file.close
file = open("Ada_Lovelace.txt",'r')
contents = file.read
puts contents
require 'open-uri'
wikipedia_article = 'https://www.wikipedia.org/wiki/Ada_Lovelace'
wikipedia = open(wikipedia_article).read
local_file = open("Ada_Lovelace.txt",'w')
local_file.write(wikipedia)
local_file.close
require 'open-uri'
wikipedia_article = 'https://www.wikipedia.org/wiki/Ada_Lovelace'
wikipedia = open(wikipedia_article).read
open("Ada_Lovelace_2.txt",'w') do |file|
file.write(wikipedia)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment