如何“打破"在一个案例中......在Ruby中 [英] How to "break" out of a case...while in Ruby
本文介绍了如何“打破"在一个案例中......在Ruby中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我尝试了 break
、next
和 return
.他们都给出错误,exit
当然有效,但完全退出.那么,如何结束一个case...when
太快了?"
So, I've tried break
, next
and return
. They all give errors, exit
of course works, but that completely exits. So, how would one end a case...when
"too soon?"
示例:
case x
when y; begin
<code here>
< ** terminate somehow ** > if something
<more code>
end
end
(以上是某种形式的伪代码,只是为了大致说明我的要求 [begin...end 用于希望 break
能够工作].
(The above is some form of pseudo-code just to give the general idea of what I'm asking [begin...end was used with the hope that break
would work].
而且,当我在做的时候,有没有更优雅的方式将块传递给case...when
?
And, while I'm at it, is there a more elegant way of passing blocks to case...when
?
推荐答案
有什么问题:
case x
when y;
<code here>
if !something
<more code>
end
end
注意 if !something
和 unless something
这篇关于如何“打破"在一个案例中......在Ruby中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文