Posted By

cczona on 03/13/08



Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Execute arbitrary code with different level of error messaging

 / Published in: Ruby


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.

  1. def silently(&block)
  2. warn_level = $VERBOSE
  3. $VERBOSE = nil
  4. result =
  5. $VERBOSE = warn_level
  6. result
  7. end
  9. # e.g.
  10. silently { require 'net/https' }

Report this snippet  

You need to login to post a comment.