Skip to content

Instantly share code, notes, and snippets.

@clicube
Created February 27, 2013 05:14
Show Gist options
  • Save clicube/5045288 to your computer and use it in GitHub Desktop.
Save clicube/5045288 to your computer and use it in GitHub Desktop.
LIMIT = {}
def limit n
key = [caller,Thread.current]
LIMIT[key] ||= n
LIMIT[key] -= 1
n = LIMIT[key]
if n > 0
n
else
LIMIT.delete key
nil
end
end
class CustomError < StandardError;end
begin
raise CustomError, "nyan" if rand() < 0.95
p "wan!"
rescue CustomError => e
p e
retry if limit 10
end
@clicube
Copy link
Author

clicube commented Feb 27, 2013

使えません

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment