Created
November 25, 2012 13:28
-
-
Save hoshinotsuyoshi/4143485 to your computer and use it in GitHub Desktop.
エラーが出るかもしれない任意のメソッドを最大n回試行するメソッド
This file contains 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 commit(symbol,*arg) | |
c = 0 | |
begin | |
return self.send(symbol.to_sym,*arg) | |
rescue | |
c += 1 | |
retry if c < 5 | |
end | |
"get less than 90 5 times..." | |
end | |
def try_to_point_get_more_than_90 | |
point = rand * 100 | |
raise Error if point < 90 | |
point | |
end | |
commit :try_to_point_get_more_than_90 | |
#=> 90.01797302249399 | |
commit :try_to_point_get_more_than_90 | |
#=> "get less than 90 5 times..." | |
commit :try_to_point_get_more_than_90 | |
#=> "get less than 90 5 times..." | |
commit :try_to_point_get_more_than_90 | |
#=> "get less than 90 5 times..." | |
commit :try_to_point_get_more_than_90 | |
#=> "get less than 90 5 times..." | |
commit :try_to_point_get_more_than_90 | |
#=> 90.45187243345141 | |
commit :try_to_point_get_more_than_90 | |
#=> "get less than 90 5 times..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment