Created
October 26, 2011 05:28
-
-
Save cmaujean/1315533 to your computer and use it in GitHub Desktop.
Rfile synopsis
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 'rfile' | |
f = RFile.new('path/to/some/file') | |
f.line(6) #=> "the 6th line in the file" | |
f.each do |l| | |
# ordered iteration of each line in the file (IO intensive) | |
end | |
# lines returned by the randomline methods are "consumed" and will not be seen in future calls | |
# if recycle == true until all lines have been seen. Once the entire file has been consumed, | |
# the index is reset and all lines will again be available. | |
f.randomline #=> "a random line from the file" | |
f.randomlines(3) #=> ["a random line", "another random line", "again, a random line"] | |
r.length #=> the number of lines available to randomline methods before the end, or before recycling | |
r.r_eof #=> true if all lines have been seen | |
r.recycle? #=> another way of accessing the recycle attribute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment