Skip to content

Instantly share code, notes, and snippets.

@squarism
Created December 12, 2011 15:44
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 squarism/1467943 to your computer and use it in GitHub Desktop.
Save squarism/1467943 to your computer and use it in GitHub Desktop.
Tempfile URL block open
require 'tempfile'
require 'open-uri'
url = "http://www.kernel.org/pub/linux/kernel/v3.x/ChangeLog-3.1"
tmp = Tempfile.new('foo')
# while this is running in irb, check out /tmp/foo*
open(url) do |f|
f.each_line {|line| tmp.write line}
end
tmp.rewind
# lazy fast forward by one line
tmp.each_line.first
puts tmp.each_line.first
# => "Author: Linus Torvalds <torvalds@linux-foundation.org>\n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment