require 'stringio'

old_stdout, new_stdout = $stdout, StringIO.new
$stdout = new_stdout

puts "Hello, World!"

$stdout = old_stdout
puts new_stdout.string

# >> Hello, World!
