summaryrefslogtreecommitdiff
path: root/lib/kernel_ext.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kernel_ext.rb')
-rw-r--r--lib/kernel_ext.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/kernel_ext.rb b/lib/kernel_ext.rb
new file mode 100644
index 0000000..b5b58e0
--- /dev/null
+++ b/lib/kernel_ext.rb
@@ -0,0 +1,28 @@
+module Kernel
+ # Sets $VERBOSE to nil for the duration of the block and back to its original
+ # value afterwards.
+ #
+ # silence_warnings do
+ # value = noisy_call # no warning voiced
+ # end
+ #
+ # noisy_call # warning voiced
+ def silence_warnings
+ 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
+ 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
+ end
+end