Bug #2020

ARGF.lineno and $. give inconsistent results

Added by telemachus (Peter Aronoff) over 11 years ago. Updated almost 10 years ago.

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


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


argf-lineno.diff (1.92 KB) argf-lineno.diff fix ARGF.lineno znz (Kazuhiro NISHIYAMA), 01/22/2010 03:03 PM

Related issues

Related to Ruby master - Bug #3022: What are $. and ARGF.lineno ?Closeddrbrain (Eric Hodel)03/27/2010Actions

Updated by znz (Kazuhiro NISHIYAMA) about 11 years ago

I reproduced on ruby 1.9.2dev (2010-01-22 trunk 26370) [x86_64-linux] too.
And I think an attached patch fixes the problem on trunk.



Updated by marcandre (Marc-Andre Lafortune) almost 11 years ago

  • Status changed from Open to Closed

Patch applied in r27308
Peter, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF