原文 http://www.wellho.net/mouth/985_Equality-in-Ruby-eql-and-equal-.html

Equality in Ruby - == eql? and equal?

The == comparison checks whether two values are equal

eql? checks if two values are equal and of the same type

equal? checks if two things are one and the same object.

How do I remember which is which ... The longer the operator, the more restrictive the test it performs

Example:

irb(main):013:0> val = 17
=> 17
irb(main):014:0> val == 17.0
=> true
irb(main):015:0> val.eql?(17.0)
=> false
irb(main):016:0> val.eql?(17)
=> true

三个等号的比较操作===
通常情况下这中方式与==是一样的,但是在某些特定情况下,===有特殊的含义:
在Range中===用于判断等号右边的对象是否包含于等号左边的Range;
正则表达式中用于判断一个字符串是否匹配模式,
Class定义===来判断一个对象是否为类的实例,
Symbol定义===来判断等号两边的符号对象是否相同。
(1..10) === 5 # true: 5属于range 1..10
/\d+/ === "123" # true: 字符串匹配这个模式
String === "s" # true: "s" 是一个字符串类的实例
:s === "s" # true
irb(main):017:0> val.equal?(17)
=> true

最新文章

  1. ASP.NET MVC5+EF6+EasyUI 后台管理系统(22)-权限管理系统-模块导航制作
  2. <<< Java提取网页源码
  3. 【LeetCode OJ】Linked List Cycle II
  4. three.js 简介
  5. CAF(C++ actor framework)使用随笔(延迟发送,消息转发,消息优先级)(四)
  6. android软键盘的用法总结
  7. Dungeon Master(poj 2251)
  8. ALTIUM 10 过孔设置开窗、不开窗
  9. SPOJ 220 Relevant Phrases of Annihilation(后缀数组+二分答案)
  10. Unity Debug类
  11. 在react.js上使用antd-design没有样式
  12. 我们必须要知道的RESTful服务最佳实践
  13. Mint-UI组件 MessageBox为prompt 添加判断条件
  14. java实现一个简单的Web服务器
  15. 钢琴培训班课程、课时及费用管理系统已提供ACM3.0新版下载
  16. C++(3):./Encryptor: undefined symbol:Z11startserviceLAKJDFLJALDKJFLLLLL
  17. 当SQL Server的实例位于集群的特定节点时,数据库无法远程访问
  18. 腾讯大数据之TDW计算引擎解析——Shuffle
  19. 弹窗中修改select默认值遇到的问题
  20. 从去除毛刺的策略看开运算opening_circle和闭运算closing_circle的异同

热门文章

  1. 【微服务架构】SpringCloud之Ribbon(四)
  2. jQuery基础入门
  3. xaml mvvm(1)之结构
  4. kali 下 apache 配置文件
  5. jquery.pagination参数释义
  6. CentOS下Docker与.netcore(一) 之 安装
  7. STM32 IAP+Ymodem功能实现(参考官方代码)
  8. linux上 查看mysql的binglog日志
  9. PHP如何根据数组中的键值进行排序
  10. 什么是cluster(群集)