From: Nobuyoshi Nakada Date: 2011-06-19T00:55:06+09:00 Subject: [ruby-core:37222] [Ruby 1.9 - Bug #4902] IO#each counts lineno Issue #4902 has been updated by Nobuyoshi Nakada. Category changed from core to DOC Assignee set to Eric Hodel Target version set to 1.9.3 ---------------------------------------- Bug #4902: IO#each counts lineno http://redmine.ruby-lang.org/issues/4902 Author: b t Status: Open 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] 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 -- http://redmine.ruby-lang.org