Skip to content

Instantly share code, notes, and snippets.

@splattael
Created January 8, 2009 15:04
Show Gist options
  • Select an option

  • Save splattael/44748 to your computer and use it in GitHub Desktop.

Select an option

Save splattael/44748 to your computer and use it in GitHub Desktop.
# http://stefankst.net/2007/06/05/capture-standard-output-in-ruby/
def capture_stdout
old_stdout = $stdout
out = StringIO.new
$stdout = out
begin
yield
ensure
$stdout = old_stdout
end
out.string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment