# Captures stdout I/O. # # @example # capture_stdout { do_something } # def capture_stdout begin $stdout = StringIO.new yield result = $stdout.string ensure $stdout = STDOUT end result end