Skip to content

Instantly share code, notes, and snippets.

@cmaujean
Created October 26, 2011 05:28
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 cmaujean/1315533 to your computer and use it in GitHub Desktop.
Save cmaujean/1315533 to your computer and use it in GitHub Desktop.
Rfile synopsis
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