mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Condense to Kernel#with_warnings
This commit is contained in:
parent
fe7d3dbb02
commit
1e72610e76
1 changed files with 8 additions and 6 deletions
|
@ -7,15 +7,17 @@ module Kernel
|
|||
#
|
||||
# noisy_call # warning voiced
|
||||
def silence_warnings
|
||||
old_verbose, $VERBOSE = $VERBOSE, nil
|
||||
yield
|
||||
ensure
|
||||
$VERBOSE = old_verbose
|
||||
with_warnings(nil) { yield }
|
||||
end
|
||||
|
||||
# Sets $VERBOSE to true for the duration of the block and back to its original value afterwards.
|
||||
def enable_warnings
|
||||
old_verbose, $VERBOSE = $VERBOSE, true
|
||||
with_warnings(true) { yield }
|
||||
end
|
||||
|
||||
# Sets $VERBOSE for the duration of the block and back to its original value afterwards.
|
||||
def with_warnings(flag)
|
||||
old_verbose, $VERBOSE = $VERBOSE, flag
|
||||
yield
|
||||
ensure
|
||||
$VERBOSE = old_verbose
|
||||
|
@ -56,4 +58,4 @@ module Kernel
|
|||
raise unless exception_classes.any? { |cls| e.kind_of?(cls) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue