Actions
Bug #4902
closedIO#each counts lineno
Description
The docs for IO#lineno state that:
lineno counts the number of times gets is called, rather than the number of newlines encountered.
However, IO#each also increases the lineno variable. Running this piece of code on a text file will print the last line number twice:
File.open('file.txt', 'r') do |f|
f.each_line do |l|
puts f.lineno
end
f.gets
puts f.lineno
end
Actions
Like0
Like0Like0