Created
December 12, 2011 15:44
-
-
Save squarism/1467943 to your computer and use it in GitHub Desktop.
Tempfile URL block open
This file contains hidden or 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 '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 <[email protected]>\n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment