Project

General

Profile

Actions

Bug #4902

closed

IO#each counts lineno

Added by bt (Bernd Homuth) over 13 years ago. Updated over 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

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
Actions #2

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

Also available in: Atom PDF

Like0
Like0Like0