From: Robert Dober Date: 2006-04-14T21:12:40+09:00 Subject: Re: Rubyesque way to do multiple <=> ------=_Part_27068_9338814.1145016757295 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 4/14/06, Victor Shepelev wrote: > > > > > > You haven't got it. I already USED first version, but I CAN'T if > > > comparison > > > is done through stand-alone function instead of <=3D> > > > > > > I have not, you are right! really sorry, I just *could* not immagine > that > > someone would implement a Custom Compare without defining <=3D>. > > 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 :) Not at all, I do not like UPPERCASE but I did not notice, I was too surprised by the fact that I indeed had missed the point. If my uppercased words have hurt your feelings, I must apoligize :( > Uppercase was only logical stress (moreover, my English is not so good, s= o > maybe I said something terrible, but I have no intention to show my "grea= t > mind" :) > Sorry my bad manners, please See above, no pbm here > What you have done is nice, but condider this too in case you can > > determine > > a reasonable BaseClass of sex. > > > > class SexBaseClass > > def <=3D>(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 <=3D> 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. > > > Ok if you can define a method <=3D> for all your objects one way or the other you are fine, if you cannot, you have to use the little extra code yo= u have written in the first place. Please do not stress about this because your original code is very correct. We are just pondering matters of philosophy here, right? Happy Easter Robert -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_27068_9338814.1145016757295--