From 1e72610e76dd678621a0606b698673bd44650f68 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 24 Mar 2009 17:03:27 -0700 Subject: Condense to Kernel#with_warnings --- .../lib/active_support/core_ext/kernel/reporting.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/kernel') diff --git a/activesupport/lib/active_support/core_ext/kernel/reporting.rb b/activesupport/lib/active_support/core_ext/kernel/reporting.rb index 0f101e8fa4..d9b84e6543 100644 --- a/activesupport/lib/active_support/core_ext/kernel/reporting.rb +++ b/activesupport/lib/active_support/core_ext/kernel/reporting.rb @@ -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 \ No newline at end of file +end -- cgit v1.2.3