which method do I have to override?

B

Boris Glawe

Hello,

I've an array filled with objects. These objects are instances of my own classes.

Which methods do I have to override in my classes that the array's uniq,
sort,... methods can successfully compare two of my objects?

I've tried to override the == method and the <=> method, but it didnt' work

thanks in advance

Boris
 
R

Ryan Leavengood

Hello,

I've an array filled with objects. These objects are instances of my own = classes.

Which methods do I have to override in my classes that the array's uniq,
sort,... methods can successfully compare two of my objects?

I've tried to override the =3D=3D method and the <=3D> method, but it did=
nt' work

Hi Boris,

For sort you just need to override <=3D>, for uniq to need to override hash=
 
E

Eric Hodel

Hello,

I've an array filled with objects. These objects are instances of
my own classes.

Which methods do I have to override in my classes that the array's
uniq, sort,... methods can successfully compare two of my objects?

I've tried to override the == method and the <=> method, but it
didnt' work

#uniq works via a Hash, so you need #hash and #eql?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top