基本知识可参考社区多篇文章:https://ruby-china.org/topics/20334等
==
方法,但是代码跟 BasicObject 的一样,可认为没有 Override;===
并不完全等于 include?
, 参数处理上略有差异;Class/Module | Override ==
|
Override eql? (Same as == ) |
Override === (Same as == ) |
---|---|---|---|
Array | √ | √(×) | × |
Hash | √ | √(√) | × |
Range | √ | √(×) | √(include? ) |
Comparable | √ | × | × |
Exception | √ | × | × |
Numeric | × | √ | x |
Complex | √ | × | × |
Float | √ | √(×) | √(√) |
Integer | √ | × | √(√) |
Rational | √ | × | × |
MatchData | √ | √(√) | × |
Method | √ | √(√) | √(call ) |
Proc | x | x | √(call ) |
Module | √ | √ | × |
Random | √ | × | × |
Regexp | √ | √(√) | √(×) |
String | √ | √(×) | √(√) |
Struct | √ | √(×) | × |
Symbol | x | x | x |
FalseClass | x | x | √ |
TrueClass | x | x | √ |
NilClass | x | x | √ |
纯体力活,每一个我都点开 c 实现源码看了。很多文章说 eql
可认为是 ==
的别名,大部分类有差异的。