Created
May 29, 2014 17:27
-
-
Save michaelminter/d45378dd9a346aa1f18c to your computer and use it in GitHub Desktop.
Ruby method for looping number of attempts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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