Ruby retry on raise
def excute_query(tried: 0) puts "tried: #{tried}" tried += 1 raise StandardError.new("error") rescue StandardError => e tried > 3 ? raise(e) : retry end end
excute_query tried: 0 tried: 1 tried: 2 tried: 3 (irb):44:in 'Object#excute_query': error (StandardError)
It turns out the tries argument can simply be augmented in the function body and is passed on when retry is called