Skip to content

Instantly share code, notes, and snippets.

Working from home

Vikas Kumar vikas027

Working from home
  • Sydney, Australia
View GitHub Profile
moertel / suppress_ruby_output.rb
Last active Feb 2, 2021
Temporarily suppress STDOUT and STDERR (ruby)
View suppress_ruby_output.rb
# Temporarily redirects STDOUT and STDERR to /dev/null
# but does print exceptions should there occur any.
# Call as:
# suppress_output { puts 'never printed' }
def suppress_output
original_stderr = $stderr.clone
original_stdout = $stdout.clone
$stderr.reopen('/dev/null', 'w'))
$stdout.reopen('/dev/null', 'w'))