【发布时间】:2011-07-03 22:10:48
【问题描述】:
在 ruby 中,我想知道是否有办法执行以下操作:
我基本上有四个可能结果的矩阵:
A is True, B is True
A is True, B is False
A is False, B is True
A is False, B is False
我想以最简洁的“红宝石方式”为此编写一个测试。
我希望做类似的事情
case[A,B]
when A && B then ...
when A && !B then ...
when !A && B then ...
when !A && !B then ...
end
...但这不起作用。那么,处理这种情况的最佳方法是什么?
【问题讨论】:
-
标准缩进将 when 置于 case 级别。
标签: ruby matrix conditional switch-statement