14 lines
286 B
Ruby
14 lines
286 B
Ruby
|
require 'stringio'
|
||
|
|
||
|
def capture(*streams)
|
||
|
streams.map! { |stream| stream.to_s }
|
||
|
begin
|
||
|
result = StringIO.new
|
||
|
streams.each { |stream| eval "$#{stream} = result" }
|
||
|
yield
|
||
|
ensure
|
||
|
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
|
||
|
end
|
||
|
result.string
|
||
|
end
|