Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在模型中为此编写 DRYer 代码:
a = 10 b = 6 if a == b a = 20 else a end
基本上,a当.a = 10a != b
a
a = 10
a != b
a = 10 b = 6 a = 20 if a == b
如果这是在一个方法中,并且您希望返回的最后一个值a:
a = 10 b = 6 a == b ? a = 20 : a
这是第三个:
您也可以使用短路运算符and
and
a = 10 b = 6 a == b and a = 20