Skip to content

Instantly share code, notes, and snippets.

@stangel
stangel / bisect.rb
Created Nov 29, 2017
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
test_proc.call(start_num, end_num)
rescue Exception => e
e.reraise if legit_exceptions.include?(e.class)
initial_fail = true