3个等于或等于大小写运算符 [英] 3 Equals or Case Equality operator

查看:89
本文介绍了3个等于或等于大小写运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ruby中,整数=== 5 返回 true 。同样, String === karthik 返回 true

但是, 5 ===整数返回 false 。和 karthik ===字符串

为什么运算符不是可交换的?

In Ruby Integer === 5 returns true. Similarly String === "karthik" returns true.
However, 5 === Integer returns false. And "karthik" === String.
Why is the operator not commutative?

推荐答案

简单的答案是:因为这没有意义。运算符描述的关系不是可交换的,为什么运算符应该是?

The simple answer is: because it doesn't make sense. The relationship the operator describes is not commutative, why should the operator be?

仅看您自己的示例: 5 是一个整数。但是 Integer 5 吗?甚至 mean 是什么?

Just look at your own examples: 5 is an Integer. But is Integer a 5? What does that even mean?

=== case包含运算符

=== is the case subsumption operator, and subsumption doesn't commute.

大小写包含运算符使用等号的事实,通常称为三等号 threequals case equal 运算符非常不幸,因为它不仅没有绝对没有什么与平等有关,但它也不符合平等所遵循的许多定律,例如传递性和您提到的可交换性。

The fact that the case subsumption operator uses equals signs, and that it is usually called the triple equals, threequals or case equality operator is terribly unfortunate since it not only has absolutely nothing to do with equality, but it also does not conform to many of the laws that equality conforms to, such as transitivity and as you mentioned commutativity.

关于 === 参见

  • What does the === operator do in Ruby?
  • === vs. == in Ruby
  • How does Integer === 3 work?

这篇关于3个等于或等于大小写运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆