Method: Kernel#silence_stream

Defined in:
lib/active_support/core_ext/kernel/reporting.rb

#silence_stream(stream) ⇒ Object

Deprecated : this method is not thread safe Silences any stream for the duration of the block.

silence_stream(STDOUT) do
  puts 'This will never be seen'
end

puts 'But this will'

This method is not thread-safe.



50
51
52
53
54
55
56
57
58
# File 'lib/active_support/core_ext/kernel/reporting.rb', line 50

def silence_stream(stream)
  old_stream = stream.dup
  stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
  stream.sync = true
  yield
ensure
  stream.reopen(old_stream)
  old_stream.close
end