Skip to content

Instantly share code, notes, and snippets.

@gacha
Created September 4, 2012 14:46
Show Gist options
  • Save gacha/3621858 to your computer and use it in GitHub Desktop.
Save gacha/3621858 to your computer and use it in GitHub Desktop.
Mute ruby output block
# Example
# mute do
# puts "Foo"
# end
# puts "Bar"
#
# Only Bar will be printed
def mute &block
orig_stdout = $stdout
$stdout = File.new('/dev/null', 'w')
yield
$stdout.close
$stdout = orig_stdout
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment