a = 2; b=2; puts a.equal?(b);为甚么是true
a=1.0; b=1.0; puts a.equal?(b) 为什么是FALSE
ruby 的equal?的一点问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- winteen 2009-09-01 16:58关注
Equality---At the +Object+ level, +==+ returns +true+ only if obj
and other are the same object. Typically, this method is
overridden in descendent classes to provide class-specific meaning.Unlike +==+, the +equal?+ method should never be overridden by
subclasses: it is used to determine object identity (that is,
+a.equal?(b)+ iff +a+ is the same object as +b+).The +eql?+ method returns +true+ if obj and anObject have the
same value. Used by +Hash+ to test members for equality. For
objects of class +Object+, +eql?+ is synonymous with +==+.
Subclasses normally continue this tradition, but there are
exceptions. +Numeric+ types, for example, perform type conversion
across +==+, but not across +eql?+, so:1 == 1.0 #=> true 1.eql? 1.0 #=> false
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥18 模拟电路问题解答有偿
- ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
- ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
- ¥15 误删注册表文件致win10无法开启
- ¥15 请问在阿里云服务器中怎么利用数据库制作网站
- ¥60 ESP32怎么烧录自启动程序
- ¥50 html2canvas超出滚动条不显示
- ¥15 java业务性能问题求解(sql,业务设计相关)
- ¥15 52810 尾椎c三个a 写蓝牙地址
- ¥15 elmos524.33 eeprom的读写问题