Challenge 3: retry With a Cap — Solution $call_count = 0 def flaky_call $call_count += 1 raise "Network error" if $call_count < 3 "Success!" end attempts = 0 begin attempts += 1 puts "Attempt #{attempts}" result = flaky_call puts result rescue => e puts "Failed: #{e.message}" retry if attempts < 3 puts "Giving up after #{attempts} attempts" end =begin Output: Attempt 1 Failed: Network error Attempt 2 Failed: Network error Attempt 3 Success! Notes: - flaky_call uses a global counter ($call_count) to simulate an operation that fails the first two times and succeeds on the third call, purely for demonstration purposes. - retry if attempts < 3 jumps back to the very top of the begin block, which re-runs attempts += 1, the puts, and the flaky_call — not just the rescue clause. - Because attempts is checked before retrying, the loop is guaranteed to stop after 3 tries even if flaky_call kept failing forever — this is the hard cap the chapter's warning about unconditional retry calls for. - On the third attempt, flaky_call succeeds, so no exception is raised at all and the rescue block never runs for that attempt — execution falls through to result = flaky_call and puts result normally. =end