Last active
December 21, 2022 23:10
-
-
Save phaedryx/5826457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
errors = [ | |
SystemStackError, LocalJumpError, IOError, RegexpError, ZeroDivisionError, | |
ThreadError, SystemCallError, SecurityError, RuntimeError, NameError, | |
RangeError, IndexError, ArgumentError, TypeError | |
] | |
module Kernel | |
def suppress_warnings | |
original_verbosity = $VERBOSE | |
$VERBOSE = nil | |
result = yield | |
$VERBOSE = original_verbosity | |
return result | |
end | |
end | |
ObjectSpace.each_object do |obj| | |
m = obj.methods.sample | |
suppress_warnings { | |
obj.instance_eval("def #{m}; raise #{errors.sample}; end", obj.method(m).source_location.to_s, rand(100)) if rand(20) < 1 rescue nil | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment