Re: Ruby and Java equality usage

On Jun 26, 2006 Matthew S. wrote:

Coming from C, I tend to think of Ruby variables as pointers to
values,
so I tend to think of the difference between eql? and == as akin to
the
following:

Ruby eql? - i.e., are they at the same spot in memory?
int* a; int* b;
a == b;

Ruby == - i.e., do they contain the same value?
int* a; int* b;
*a == *b;

The equals? method checks identity. As it says here,
class Object - RDoc Documentation, the eql?
method can be and usually is overridden to be synonymous with ==. If
you put your objects in a hash you’re going to want to override hash and
eql? to have equivalent semantics.

Having three separate equality methods leads to this kind of confusion.
You need two (identity and value equality) but not 3 IHMO.

Steve

Oops… it looks like I’ve touched a nice one :slight_smile: (but somehow I am
happy that my confusion has basis)

./alex

.w( the_mindstorm )p.

(http://themindstorms.blogspot.com)