Module: AttemptTo
- Defined in:
- lib/attempt_to/version.rb,
lib/attempt_to/attempt_to.rb
Constant Summary collapse
- VERSION =
"0.3"
Class Method Summary collapse
Class Method Details
.attempt_to(something, amount) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/attempt_to/attempt_to.rb', line 4 def self.attempt_to(something, amount) amount.times { |times| begin return yield rescue Exception => ex Kernel.puts "Failed attempt ##{times+1} to #{something}. Error message: #{ex.}" if times+1 == amount Kernel.puts "Attempted #{amount} times to #{something}. Giving up..." exit end end } end |