Created
September 11, 2013 02:52
-
-
Save roryokane/6518793 to your computer and use it in GitHub Desktop.
Ruby method `with_stdout` lets you output to an arbitrary stream with `puts`, etc., for convenience
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
# lets you output to an arbitrary stream with `puts`, etc., for convenience | |
def with_stdout(new_stdout) | |
old_stdout = $stdout # $stdout usually be STDOUT here, but not if you nest this function | |
$stdout = new_stdout | |
yield | |
$stdout = old_stdout | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment