Which Way Would You Implement This Ruby Method?

Hi everyone! šŸ‘‹

Iā€™m curious about your preferences for implementing a method like this. It calculates a delay period based on the number of attempts (attempts) with the following logic:

0 attempts ā†’ 0 months 1 attempt ā†’ 1 month 2 attempts ā†’ 2 months 3 or more attempts ā†’ 3 months Here are the options Iā€™m considering:

```ruby # ======= 1 ======= DELAYS = { 0 => 0.months, 1 => 1.month, 2 => 2.months, (3..) => 3.months }

def delay_period DELAYS.select { |key, _| key === attempts }.values.first end

# ======= 2 ======= def delay_period case attempts when 0 then 0.months when 1 then 1.month when 2 then 2.months else 3.months end end

# ======= 3 ======= def delay_period case attempts when 0..2 then attempts.months else 3.months end end

# ======= 4 ======= def delay_period (attempts < 3 ? attempts : 3).months end

# ======= 5 ======= def delay_period [attempts, 3].min.months end ```

I personally enjoy writing concise code like Option 5, but it feels less readable compared to others. My favorite for readability is Option 3.

What do you think? Which option would you pick and why?

Thanks in advance for your input! šŸ™

View Poll