zoukankan      html  css  js  c++  java
  • ruby中的== eql?和equal?区别

    原文 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
     

  • 相关阅读:
    分词器下载地址
    solr 查询方式
    solr 到 lucene
    Solr 安装与使用 Centos7
    线性表-串:KMP模式匹配算法
    金山——弱智的翻译程序
    FL2440移植Linux2.6.33.7内核
    FL2440移植u-boot2011.09
    【转】C/C++除法实现方式及负数取模详解
    循环缓冲类
  • 原文地址:https://www.cnblogs.com/or2-/p/6565337.html
Copyright © 2011-2022 走看看