Project

General

Profile

Actions

Bug #13051

closed

Object created with ARGF.class.new fails to update .lineno in .each

Added by lucasbuchala (Lucas Buchala) about 8 years ago. Updated about 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0rc1 (2016-12-12 trunk 57064) [i686-linux]
[ruby-core:78728]

Description

I don't know if this way of creating ARGF-like objects is supported or not.
I just noticed that it didn't update the .lineno when used in .each.

Consider the example input file:

$ cat file1
foo
bar
baz

The following code:

f = ARGF.class.new('file1')

f.each do |line|
  puts "#{f.lineno} #{line}"
end

Outputs this:

0 foo
0 bar
0 baz

I was expecting this:

1 foo
2 bar
3 baz

If, instead of using .each, I read it in 2 steps with: while line = f.gets; puts f.lineno; ..., then it works, the line numbers are updated.

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Status changed from Open to Closed

Applied in changeset r57124.


io.c: update argf lineno

Actions

Also available in: Atom PDF

Like0
Like0