[#109207] [Ruby master Feature#18915] New error class: NotImplementedYetError or scope change for NotImplementedYet — Quintasan <noreply@...>
Issue #18915 has been reported by Quintasan (Michał Zając).
18 messages
2022/07/14
[ruby-core:109229] [Ruby master Bug#18909] ARGF.readlines reads more than current file
From:
"JohanJosefsson (Johan Josefsson)" <noreply@...>
Date:
2022-07-16 10:25:44 UTC
List:
ruby-core #109229
Issue #18909 has been updated by JohanJosefsson (Johan Josefsson).
austin (Austin Ziegler) wrote in #note-10:
...
In your link it is clear that e.g. in the case of read, ARGF concatenates the input files, not that it always treats the input as a concatenated file. (That third paragraph.) It is also very clear that readlines operates on the current file, not on a concatenated input file.
I see a use case for this specified behavior and I cannot see why this could not be kept and the implementation be updated to conform. (I.e. apart from practical problems.) Kernel.readlines still operates on the concatenated file if that behavior is needed.
My reference toy example:
I want to prepend every specified file with a linecount. Here I have implemented ARGF.readlines according to the original spec and the task becomes very simple:
$ cat a b
primo
secundo
PRIMO
$ ruby -r ./argf_readlines.rb -i.bak -e 'while x=argf_readlines do puts "#{x.size} lines:";puts x end' a b
$ cat a b
2 lines:
primo
secundo
1 lines:
PRIMO
Maybe a feature request for an added function #readlines_current would make us all happy?
(I cannot intuitively see what a function #each_file would do so I cannot comment on that.)
PS: the documentation of the inplace_mode methods is not correct. I will make a report on that.
----------------------------------------
Bug #18909: ARGF.readlines reads more than current file
https://bugs.ruby-lang.org/issues/18909#change-98365
* Author: JohanJosefsson (Johan Josefsson)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
* Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED
----------------------------------------
The docuentation says that ARGF.readlines: *Reads ARGF's current file in its entirety* , but this is what happens:
`$ cat fileA
A
$ cat fileB
B
$ ruby -e 'puts ARGF.readlines' fileA fileB
A
B`
i.e. it reads both the current file and the next one (all files?).
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>