blob: a947eebf6fece310ad4387a3a5174999b45e062e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# frozen_string_literal: true
require "stringio"
def capture(*args)
opts = args.pop if args.last.is_a?(Hash)
opts ||= {}
args.map!(&:to_s)
begin
result = StringIO.new
result.close if opts[:closed]
args.each {|stream| eval "$#{stream} = result" }
yield
ensure
args.each {|stream| eval("$#{stream} = #{stream.upcase}") }
end
result.string
end
|