You haven’t got it. I already USED first version, but I CAN’T if
comparison
is done through stand-alone function instead of <=>
I have not, you are right! really sorry, I just could not immagine that
someone would implement a Custom Compare without defining <=>.
But as it is you have of course a problem.
Forgive my answer sometimes there are beginners posting.
The next time however, before replying, I might read the question.
I thinks, there is a bit of irony
If my uppercased words have hurt your feelings, I must apoligize
Uppercase was only logical stress (moreover, my English is not so good,
so
maybe I said something terrible, but I have no intention to show my
“great
mind”
Sorry my bad manners, please
What you have done is nice, but condider this too in case you can
determine
a reasonable BaseClass of sex.
class SexBaseClass
def <=>(other)
ComplexCompareFunction self, other
end
end
Yes, I know this way, but I really can’t use it. Here is more real
example:
class Product
attr_accessor :type, :field1, :field2, field3
end
If @type is “HDD”, @field1 is string representing hdd size (120 Gb, 80
Gb
and so on): comparison must be done as field1.to_i <=> other.field1.to_i
If @type is “drive”, @field1 is drive type (“cd-r”, “cd-rw”, “dvd” …)
and
comparison must be done in a strange way (“cd-XXX” > “dvd-XXXX”, but
“cd-rom” < “cd-r” < “cd-rw”).
OK, you would ask, why I’ve used one “general” class Product instead of
concrete HDD, CPU, Drive and so on? Because product type can be changed
dynamically (it is guessed by product full name, on wrong guess user can
change @type manually through GUI).
So, my question is still actual.
Hope I got it
Robert
Victor.