Bug #2020: ARGF.lineno and $. give inconsistent results
http://redmine.ruby-lang.org/issues/show/2020

Author: Peter Aronoff
Status: Open, Priority: Normal
ruby -v: ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin9.7.1]

When using ARGF on Ruby 1.9.1 (rev. 24175), ARGF.lineno gives a result of '0' for all lines. $. works as expected.

This script shows the problem: 

#!/usr/bin/env ruby -w

ARGF.each do |line|
  print "With [lineno]:\t"
  print ARGF.lineno, ': ', line  
  print "With [$.]:\t"
  print $., ': ', line  
end

If I run this with Ruby 1.8.6 (OS X's system Ruby), the output from $. and ARGF.lineno is identical. With 1.9.1, I get this:

telemachus ~ $ ./cat.rb test.txt 
With [lineno]:	0: This is line one.
With [$.]:	1: This is line one.
With [lineno]:	0: Here is line two.
With [$.]:	2: Here is line two.
With [lineno]:	0: A third line for fun.
With [$.]:	3: A third line for fun.

Thanks, T


----------------------------------------
http://redmine.ruby-lang.org