Created
September 30, 2016 09:16
-
-
Save janlelis/fe52f521e3ae6e9cbd89ac687bcd8906 to your computer and use it in GitHub Desktop.
This file contains 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
require "stringio" | |
def capture_stdout | |
capture = StringIO.new | |
restore, $stdout = $stdout, capture | |
yield | |
$stdout = restore | |
capture.string | |
end | |
def capture_stderr | |
capture = StringIO.new | |
restore, $stderr = $stderr, capture | |
yield | |
$stderr = restore | |
capture.string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment