Skip to content

Instantly share code, notes, and snippets.

@phaedryx phaedryx/chaos.rb
Last active Dec 18, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.