case search_term
when 'a'
ptr = 0
when 'b'
ptr = 1
when 'c'
ptr = 2
else
ptr = 99
end
if location = 'xyz' and search_term = 'c'
ptr = 0
end
有什么方法可以在 case 语句中包含上面的 if 吗?
最佳答案
ptr = case search_term
when 'a'
0
when 'b'
1
when 'c'
if location == 'xyz' then #note the ==
0
else
2
end
else
99
end
关于ruby - 无论如何我可以使用 if else inside ruby case..end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40537082/