Closed
Description
For methods that print to standard output (benchmark
, bm
, and bmbm
), it would be nice to be able to specify that they go to another stream instead, such as an open file or a string buffer (StringIO
), or even $stdout
, in case it has been changed to something other than STDOUT
.
In cases where the method signature would not support another parameter, an alternate method could be added in which the stream is a parameter, the body of the original method moved there, and the original method remaining to call the new method with STDOUT
, e.g.:
def benchmark(caption = "", label_width = nil, format = nil, *labels)
...
end
...could become...
def benchmark_to(output_stream, caption = "", label_width = nil, format = nil, *labels)
# body of original benchmark method
end
...and...
def benchmark(caption = "", label_width = nil, format = nil, *labels)
benchmark_to(STDOUT, caption, label_width, format, *labels)
end
I believe all the likely objects for output would support puts
, print
, etc. I'm not sure about sync
, but I suppose we could put a respond_to?
guard around that call.
Metadata
Metadata
Assignees
Labels
No labels