Project

General

Profile

Bug #4902

IO#each counts lineno

Added by Bernd Homuth over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
ruby -v:
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
Backport:
2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
[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

Associated revisions

Revision 32465
Added by Eric Hodel over 4 years ago

  • io.c: Note that methods other than IO#gets may increase IO#lineno. [Ruby 1.9 - Bug #4902]

Revision 32465
Added by Eric Hodel over 4 years ago

  • io.c: Note that methods other than IO#gets may increase IO#lineno. [Ruby 1.9 - Bug #4902]

History

#1 [ruby-core:37222] Updated by Nobuyoshi Nakada over 4 years ago

  • Category changed from core to doc
  • Assignee set to Eric Hodel
  • Target version set to 1.9.3

#2 Updated by Eric Hodel over 4 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]

Also available in: Atom PDF