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
Updated by nobu (Nobuyoshi Nakada) over 13 years ago
- Category changed from core to doc
- Assignee set to drbrain (Eric Hodel)
- Target version set to 1.9.3
Updated by drbrain (Eric Hodel) over 13 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r32465.
b, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- io.c: Note that methods other than IO#gets may increase IO#lineno.
[Ruby 1.9 - Bug #4902]
Actions
Like0
Like0Like0