[#104307] Float truncate — Eustáquio Rangel <eustaquiorangel@...>
Hi!
4 messages
2021/06/16
[ruby-core:104348] [Ruby master Feature#17994] Clarify `IO.read` behavior and add `File.read` method
From:
mame@...
Date:
2021-06-17 17:29:14 UTC
List:
ruby-core #104348
Issue #17994 has been updated by mame (Yusuke Endoh).
Jeremy, thanks you for your comment.
jeremyevans0 (Jeremy Evans) wrote in #note-1:
> Honestly, I don't think `read` makes sense as a class method on socket classes, so maybe we can avoid the issue by undefing it (after a deprecation period).
It makes sense. Because undefing all subclasses is a bit annoying (and we cannot change user-defined subclasses of IO), it may be good for `IO.read` to raise an exception when the reciever is neither `IO` or `File`. I'd like to bring the deprecation to the agenda of the next dev-meeting.
BTW, do you have any concern against merging my current PR? It just clarifies the current behavior of IO.read and adds `File.read` alias. We can implement the deprecation warnings later if it is approved.
----------------------------------------
Feature #17994: Clarify `IO.read` behavior and add `File.read` method
https://bugs.ruby-lang.org/issues/17994#change-92573
* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
----------------------------------------
`IO.read` creates a subprocess when a given file name starts with a `|` character.
```
irb(main):001:0> IO.read("| ls /etc/passwd")
=> "/etc/passwd\n"
```
To disable this feature, `File.read` can be used.
```
irb(main):002:0> File.read("| ls /etc/passwd")
(irb):2:in `read': No such file or directory @ rb_sysopen - | ls /etc/passwd (Errno::ENOENT)
```
So, as far as I know, `File.read` is more prefereable to `IO.read` if a user want to just read a file.
However, in terms of the implementation, there is no definition of `File.read`. `File.read` invokes `IO.read` because `IO` is a superclass of `File`, and `IO.read` creates a subprocess only when its receiver is exactly the `IO` class.
I think there are two problems in the current situation:
1. The rdoc of `IO.read` does not explain the behavior to disable a subprocess invocation.
2. The rdoc does not have an entry for `File.read`.
I've created a PR to address the two issues by clarifying `IO.read` behavior and defining `File.read` as an alias to `IO.read`.
https://github.com/ruby/ruby/pull/4579
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>