This question already has an answer here:
- Ruby range: operators in case statement 3 answers
Is there a way to use a case
statement with integer comparisons in ruby? I have found lots of examples comparing strings, but my case
example below fails with syntax errors.
def get_price_rank(price)
case price
when <= 40
return 'Cheap!'
when 41..50
return 'Sorta cheap'
when 50..60
return 'Reasonable'
when 60..70
return 'Not cheap'
when 70..80
return 'Spendy'
when 80..90
return 'Expensive!'
when >= 90
return 'Rich!'
end
end