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.
我有两个变量a和b. 我想比较两者a和b一个值,比如说10。
a
b
10
我可以这样做:
10 == a && 10 == b
但是,我想知道是否有任何方法可以将它写成一个表达式?(例如喜欢a == b == 10)
a == b == 10
[a,b,3].all? {|x| x==10}
但在这种情况下
[].all? {|x| x==10}
也将返回 true
在来自 aztaroth 的评论后更新:
[a,b].uniq == [10]