Skip to content

Instantly share code, notes, and snippets.

stangel / bisect.rb
Created November 29, 2017 22:54
Bisect a proc that takes two numeric arguments and raises an exception when the error condition is between them
View bisect.rb
def bisect(start_num, end_num, test_proc)
# calling test_proc(start_num, end_num) should raise an exception on failure
legit_exceptions = [SystemExit, NoMethodError]
initial_fail = nil
begin, end_num)
rescue Exception => e
e.reraise if legit_exceptions.include?(e.class)
initial_fail = true