Return to Snippet

Revision: 5516
at March 13, 2008 03:27 by cczona


Initial Code
def silently(&block)
  warn_level = $VERBOSE
  $VERBOSE = nil
  result = block.call
  $VERBOSE = warn_level
  result
end

# e.g.
silently { require 'net/https' }

Initial URL
http://www.caliban.org/ruby/rubyguide.shtml

Initial Description
You can turn off warnings for a section of your code by setting $VERBOSE to nil. Even better is to codify this in a method.  Since this method takes a block as its parameter, you can now pass it arbitrary chunks of code to execute without warnings.

Initial Title
Execute arbitrary code with different level of error messaging

Initial Tags
ruby

Initial Language
Ruby