It seemed useful to be able to silence more than one stream at a time.
# Silences any stream for the duration of the block.
#
# silence_stream(STDOUT) do
# puts 'This will never be seen'
# end
#
# puts 'But this will'
def silence_stream(*streams)
streams = [STDOUT, STDERR] if streams.empty?
old = {}
streams.each do |stream|
old[stream] = stream.dup
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
stream.sync = true
yield
end
ensure
streams.each do |stream|
stream.reopen(old[stream])
end
end
alias_method :silently, :silence_stream
T.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---