rubyでエラーが出たら何回か繰り返す処理

class Sample
  def test
    ---
    ---
    count_retry = 0
    begin
      // somethings
    rescue
      count_retry += 1
      retry if count_retry < 3
    end
  end
end