Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Created May 29, 2014 17:27
Show Gist options
  • Save michaelminter/d45378dd9a346aa1f18c to your computer and use it in GitHub Desktop.
Save michaelminter/d45378dd9a346aa1f18c to your computer and use it in GitHub Desktop.
Ruby method for looping number of attempts
def insist(max_attempts: 3, &block)
attempts = 0
begin
yield
rescue SomeException => e
attempts += 1
retry if attempts < max_attempts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment