Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The return value of ARGF.file#lineno differs from that of MRI #4497

Closed
nico-hn opened this issue Feb 20, 2017 · 0 comments
Closed

The return value of ARGF.file#lineno differs from that of MRI #4497

nico-hn opened this issue Feb 20, 2017 · 0 comments
Labels
Milestone

Comments

@nico-hn
Copy link

nico-hn commented Feb 20, 2017

Environment

Expected Behavior

When you read several files via ARGF, the value of ARGF.file#lineno is expected to be reset to 1 each time a new file is read from command line arguments.

I cannot find an appropriate explanation in ruby-doc.org, but in the documentation in Japanese, it is explained that ARGF.lineno returns the current line number as if the lines are read from a single file consisting of files given as command line arguments, while ARGF.file#lineno returns the line number for an individual file in the arguments. And this is the actual behavior of MRI.

The behavior of JRuby seems to be the same as ARGF.lineno.

Actual Behavior

Supposing you have 3 files first.txt, second.txt and third.txt whose lines are "a b c", "A B C D" and "alpha beta" respectively:

$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

$ ruby -ne 'print "#{ARGF.filename}:#{ARGF.file.lineno}: #{$_}"' first.txt second.txt third.txt
first.txt:1: a
first.txt:2: b
first.txt:3: c
second.txt:1: A
second.txt:2: B
second.txt:3: C
second.txt:4: D
third.txt:1: alpha
third.txt:2: beta

$ ruby -v                                                                                      
jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 23.5-b02 on 1.7.0_09-b05 +jit [linux-x86_64]

$ ruby -ne 'print "#{ARGF.filename}:#{ARGF.file.lineno}: #{$_}"' first.txt second.txt third.txt
first.txt:1: a
first.txt:2: b
first.txt:3: c
second.txt:4: A
second.txt:5: B
second.txt:6: C
second.txt:7: D
third.txt:8: alpha
third.txt:9: beta

@enebo enebo added this to the JRuby 9.1.8.0 milestone Feb 27, 2017
@enebo enebo added the core label Feb 27, 2017
@enebo enebo closed this as completed in b9476c4 Feb 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants