Project

General

Profile

Feature #12006

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

Added by duerst (Martin Dürst) over 3 years ago. Updated over 3 years ago.

Status:
Open
Priority:
Normal
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

History

Updated by duerst (Martin Dürst) over 3 years ago

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

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

Also available in: Atom PDF