summaryrefslogtreecommitdiff
path: root/lib/kernel_ext.rb
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-05-25 14:56:20 +0200
committerAzul <azul@riseup.net>2016-05-25 14:56:20 +0200
commit9598e42722c13030b757b7b4ab47de0d50228d5c (patch)
tree57e92123d84c8edfd9ab09fad2359bbbacb1e572 /lib/kernel_ext.rb
parentc90b23b4b4a4f550d6e2f0ce6dc0cc2b6fc1a2d5 (diff)
silence some warnings from evma_httpserver
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