从 switch 语句获取控制变量
ruby 中 switch 语句的基本语法是
case expression
when condition1
statements1
when condition2
statements2
else
statements
end
有没有办法在语句中获取控制表达式值?
意思是,是否有一些变量存储可以直接使用的表达式值 - 并且表达式不需要在语句体中再次调用?
the basic syntax of switch statement in ruby is
case expression
when condition1
statements1
when condition2
statements2
else
statements
end
Is there a way to get control expression value in statements?
Means, is there some variable which stores expression value which can be used directly - and expression need not be called again in statements body?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有魔法变量。使用普通变量并不麻烦:
There is no magic variable. It's no trouble to use an ordinary variable:
不,没有。但你可以这样做:
No, there isn't. But you can just do this:
自己内联分配变量很简单:
It's straightforward to assign the variable yourself inline: