ruby几个易被忽略的操作符

==         值相等  
eql?     值相等,类型相等  
equal? 值相等,内存地址相等

 

    a = 1
    b = 1.0
    c = 1.0
    d = 1.0
    e = c

    puts a == b     # => true
    puts a.eql? b   # => false
    puts c.equal? d # => false
    puts c.equal? e # => true

 

你可能感兴趣的:(C++,c,C#,Ruby)