Skip to content

Instantly share code, notes, and snippets.

@alexch
Created August 9, 2010 00:53
Show Gist options
  • Save alexch/514760 to your computer and use it in GitHub Desktop.
Save alexch/514760 to your computer and use it in GitHub Desktop.
def capturing_output
original = $stdout
captured = StringIO.new
$stdout = captured
yield
captured.string
ensure
# allow nesting
if original.is_a? StringIO
original << captured.string
end
$stdout = original
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment