1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/bundler/support/streams.rb

20 lines
378 B
Ruby
Raw Normal View History

# 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