From: akr@... Date: 2021-07-15T05:18:29+00:00 Subject: [ruby-core:104606] [Ruby master Feature#17994] Clarify `IO.read` behavior and add `File.read` method Issue #17994 has been updated by akr (Akira Tanaka). I feel adding File.read method is uselessly complex behavior: Socket.read (no pipe) inherits IO.read (support pipe) but behaves as File.read (no pipe). Also, adding method require more document maintenance cost. So, I think updating the document of IO.read is best way to go. I think disabling Socket.read has very few benefit over its effect: I guess someone would propose disabling other class methods as well. ---------------------------------------- Feature #17994: Clarify `IO.read` behavior and add `File.read` method https://bugs.ruby-lang.org/issues/17994#change-92893 * 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: