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
so I tend to think of the difference between eql? and == as akin to

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,, 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.


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


.w( the_mindstorm )p.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs