Skip to content

Instantly share code, notes, and snippets.

@phaedryx
Last active December 21, 2022 23:10
Show Gist options
  • Save phaedryx/5826457 to your computer and use it in GitHub Desktop.
Save phaedryx/5826457 to your computer and use it in GitHub Desktop.
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