Skip to content

Instantly share code, notes, and snippets.

@stevenyap
Created October 30, 2014 05:23
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 stevenyap/1eb6c8ec3a71fca8ac29 to your computer and use it in GitHub Desktop.
Save stevenyap/1eb6c8ec3a71fca8ac29 to your computer and use it in GitHub Desktop.
Capture/Suppress output via STOUT, STDERR, etc

Suppress all outputs:

quietly { puts 'this message will not be shown'}

Suppress outputs except error messages (eg STDERR):

silence_stream(STDOUT) do
  puts 'This will never be seen'
end

puts 'But this will'

Capture the outputs:

stream = capture(:stdout) { puts 'notice' }
stream # => 'notice'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment