[英]Ruby - Case Statement help
我有一个案例声明,内容如下:
case @type
when "normal"
when "return"
else
end
效果很好,但我想添加以下内容:
case @type
when "normal"
when "return"
when @type length > 1, and contains no spaces
else
end
那有效/安全吗?
如果您与@type的值不匹配,则不要在case语句后立即添加它,而要在when子句中添加它:
case
when @type=="normal" then "blah"
when @type=="return" then "blah blah"
when (@type.length>1 and !@type.include?(' ')) then "blah blah blah"
else
end
也许这个?
@type[/^[^\s]{2,}$/]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.