/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class Integer def tries options = {}, &block return if self < 1 yield attempts ||= 1 rescue options[:ignoring] || Exception retry if (attempts += 1) <= self end end 3.tries { open 'http://vision-media.ca' } 3.tries do |i| puts "Try ##{i} at opening..." open 'http://vision-media.ca' end 3.tries(:ignoring => ParticularException) do open 'http://vision-media.ca' end