4
有没有办法在ruby中使用整数比较的case
语句?我发现了很多比较字符串的例子,但我的case
下面的例子失败,语法错误。ruby case case statement and compare
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
[Ruby范围:操作符在case语句中]的可能重复(http://stackoverflow.com/questions/16065244/ruby-range-operators-in-case-statement)或http://stackoverflow.com/questions/18630872 /如何对生成定制-case语句功能于红宝石/ 18631204#18631204 – knut