| Ruby | Java |
Object#equal? | == |
Object#eql? | Object.equals |
Object#== | Object.equals |
Object#=== | N/A |
Object#equal?, respectively the == operator).Another similarity is for objects used as keys in maps (hashes). If you want to customize their behavior, in both Ruby and Java will have to override
Object#eql? and Object#hash, respectively Object.equals() and Object.hashCode(). And that would be it with the similarities.In Ruby world,
Object#eql? and Object?== are named equivalence. I haven't been able to find out the reasons for having both Object#eql? and Object?== and the only example I have found is the following:
2.eql? 2.0 => false 2 == 2.0 => trueRuby has another equality method
Object#=== and this one is used only in case statements.Reference:
- The Ruby Way
- Programming Ruby- The Pragmatic Programmer's Guide 2nd Ed (known also as the ~PickAxe book)
- Object#==
- Object#===
- Object#eql?
- Object#equal?
- Object.equals
- comparing objects
- which method do I have to override?
- hash and ==
- identity
- equivalence relation

