gpt4 book ai didi

Ruby on rails Case when 语句不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 17:44:46 25 4
gpt4 key购买 nike

我不明白为什么我的 case/when 语句不起作用...我找不到很多关于“AND (&&)”运算符的信息。

points = -180
case points
when (points >= -9999) && (points < -300) then
title = "bad player"
when (points >= -300) && (points < -100) then
title = "not reliable"
when (points >= -100) && (points < 100) then
title = "Newbie"
end

我得到 title = blank..

谢谢

最佳答案

试试这个

points = -180
case
when (points >= -9999) && (points < -300)
title = "bad player"
when (points >= -300) && (points < -100)
title = "not reliable"
when (points >= -100) && (points < 100)
title = "Newbie"
end

#=> "not reliable"

你也可以使用范围

points = -180

title =
case points
when -9999..-301
"bad player"
when -300..-99
"not reliable"
when -100..99
"Newbie"
end


#=> "not reliable"

关于Ruby on rails Case when 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42070080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com