[英]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.