Reputation: 23
I want to gain some insight into how Ruby manages file buffering. I looked elsewhere for the answers, but I guess I'm not asking the right questions.
In an IRB session I opened a file for reading:
f = File.open('somefile.txt', 'r')
Using this command:
puts f.gets
prints out the first line of somefile.txt
. If I repeat the puts f.gets
command, I get the second line, and so on.
My questions are:
gets
?gets
has some record of the last line of the file that it read. Is there any way to find out the value of this line index?Upvotes: 2
Views: 109
Reputation: 1300
f.lineno
will give you the current line number
f.pos
will give you the current offset in bytes
Upvotes: 1