Skip to content

Instantly share code, notes, and snippets.

@janlelis
Created September 30, 2016 09:16
Show Gist options
  • Save janlelis/fe52f521e3ae6e9cbd89ac687bcd8906 to your computer and use it in GitHub Desktop.
Save janlelis/fe52f521e3ae6e9cbd89ac687bcd8906 to your computer and use it in GitHub Desktop.
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