2 # Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.
5 # value = noisy_call # no warning voiced
8 # noisy_call # warning voiced
10 old_verbose
, $VERBOSE = $VERBOSE, nil
13 $VERBOSE = old_verbose
16 # Sets $VERBOSE to true for the duration of the block and back to its original value afterwards.
18 old_verbose
, $VERBOSE = $VERBOSE, true
21 $VERBOSE = old_verbose
25 def silence_stderr
#:nodoc:
26 silence_stream(STDERR) { yield }
29 # Silences any stream for the duration of the block.
31 # silence_stream(STDOUT) do
32 # puts 'This will never be seen'
35 # puts 'But this will'
36 def silence_stream(stream
)
37 old_stream
= stream
.dup
38 stream
.reopen(RUBY_PLATFORM =~
/mswin/ ? 'NUL:' : '/dev/null')
42 stream
.reopen(old_stream
)
45 # Blocks and ignores any exception passed as argument if raised within the block.
47 # suppress(ZeroDivisionError) do
49 # puts "This code is NOT reached"
52 # puts "This code gets executed and nothing related to ZeroDivisionError was seen"
53 def suppress(*exception_classes
)
56 raise unless exception_classes
.any
? { |cls
| e
.kind_of
?(cls
) }