Actions
Feature #12006
openreturn IO object from IO#print, IO#puts, IO#close_read, IO#close_write,...
Status:
Open
Assignee:
-
Target version:
-
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
Like0
Like0