It seemed useful to be able to silence more than one stream at a time.
# Silences any stream for the duration of the block.
It seemed useful to be able to silence more than one stream at a time.
# Silences any stream for the duration of the block.
Of course, it would help if I put 'yield' in the right place. Try
again:
def silence_stream(*streams)
streams = [STDOUT, STDERR] if streams.empty?
on_hold = streams.collect{ |stream| stream.dup }
streams.each do |stream|
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
stream.sync = true
end
yield
ensure
streams.each_with_index do |stream, i|
stream.reopen(on_hold[i])
end
end
T.