Created
September 4, 2012 14:46
-
-
Save gacha/3621858 to your computer and use it in GitHub Desktop.
Mute ruby output block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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