Ruby Tries Method


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class Integer
  2. def tries options = {}, &block
  3. return if self < 1
  4. yield attempts ||= 1
  5. rescue options[:ignoring] || Exception
  6. retry if (attempts += 1) <= self
  7. end
  8. end
  9.  
  10. 3.tries { open 'http://vision-media.ca' }
  11.  
  12. 3.tries do |i|
  13. puts "Try ##{i} at opening..."
  14. open 'http://vision-media.ca'
  15. end
  16.  
  17. 3.tries(:ignoring => ParticularException) do
  18. open 'http://vision-media.ca'
  19. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.