Skip to content

Instantly share code, notes, and snippets.

@wbailey
Created March 28, 2011 05:55
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 wbailey/890051 to your computer and use it in GitHub Desktop.
Save wbailey/890051 to your computer and use it in GitHub Desktop.
require 'stringio'
def capture_stdout
$stdout = StringIO.new
$stdin = StringIO.new("y\n")
yield
$stdout.string.strip
ensure
$stdout = STDOUT
$stdin = STDIN
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment