Created
February 27, 2010 16:14
-
-
Save tomoya55/316796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# via http://ujihisa.blogspot.com/2010/02/redirecting-stdout.html | |
def capture_io | |
require 'stringio' | |
orig_stdout, orig_stderr = $stdout, $stderr | |
captured_stdout, captured_stderr = StringIO.new, StringIO.new | |
$stdout, $stderr = captured_stdout, captured_stderr | |
yield | |
return captured_stdout.string, captured_stderr.string | |
ensure | |
$stdout = orig_stdout | |
$stderr = orig_stderr | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment