Bug #2020
closedARGF.lineno and $. give inconsistent results
Description
=begin
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
=end
Files
Updated by znz (Kazuhiro NISHIYAMA) almost 15 years ago
- File argf-lineno.diff argf-lineno.diff added
- Category set to core
=begin
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.
=end
Updated by marcandre (Marc-Andre Lafortune) over 14 years ago
- Status changed from Open to Closed
=begin
Patch applied in r27308
Peter, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end