Bug #4902

IO#each counts lineno

Added by Bernd Homuth almost 3 years ago. Updated almost 3 years ago.

[ruby-core:37221]
Status:Closed
Priority:Normal
Assignee:Eric Hodel
Category:doc
Target version:1.9.3
ruby -v:ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0] Backport:

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 almost 3 years ago

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

History

#1 Updated by Nobuyoshi Nakada almost 3 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 almost 3 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