Skip to content

Instantly share code, notes, and snippets.

@roryokane
Created September 11, 2013 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roryokane/6518793 to your computer and use it in GitHub Desktop.
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
# 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