Project

General

Profile

Actions

Feature #12006

open

return IO object from IO#print, IO#puts, IO#close_read, IO#close_write,...

Added by duerst (Martin Dürst) almost 9 years ago. Updated almost 9 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:72926]

Description

There are a number of methods on IO objects that currently return nil.
It would be more convenient if they returned the object itself; that way, the methods could be chained.

Although some people might disagree with this style, this would allow e.g. to write something like

output = IO.popen(command, 'r+') do |pipe|
pipe << input
pipe.close_write
pipe.read
end

as:

output = IO.popen(command, 'r+') do |pipe|
pipe.print(input).close_write.read
end

Updated by duerst (Martin Dürst) almost 9 years ago

Here is another example: Simplfy
$stdout.puts "some message"
$stdout.flush

to:
$stdout.puts("some message").flush

Actions

Also available in: Atom PDF

Like0
Like0