Project

General

Profile

Actions

Bug #4902

closed

IO#each counts lineno

Added by bt (Bernd Homuth) almost 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
Backport:
[ruby-core:37221]

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

Also available in: Atom PDF

Like0
Like0Like0