So, in both Ruby and Java we have an instance reference equality or identity (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 => true

Ruby has another equality method Object#=== and this one is used only in case statements.

Labels:

Related Posts

5
comments:

By the way, ri is pretty informative too: ------------------------------------------------------------ Object#eql? obj == other => true or false obj.equal?(other) => true or false obj.eql?(other) => true or false------------------------------------------------------------------------ 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:

Tags

Archive

myNoSQL a NoSQL blog featuring the best daily NoSQL news, articles and links covering all major NoSQL projects and following closely all things related to NoSQL ecosystem. Everything you need and want to know about NoSQL