From: gabriele renzi Date: 2005-12-12T06:37:37+09:00 Subject: Re: creating a <=> method Dirk Meijer ha scritto: > hi everyone, > i've created a class, and want it to be comparable with itself, but i don't > know what to place inside the <=> method. > the basic idea is that one of the values of the class (which is a symbol) is > converted to a string, which is then compared. > greetings, Dirk. > yuu should return 1 if self > b, 0 if self == b and -1 otherwise. You can generally realy on some other <=>, i.e. >> Foo= Struct.new :someval do ?> def <=> other >> someval.to_s <=> other.someval.to_s >> end >> include Comparable >> end => Foo >> f1=Foo.new "ciao" => # >> f2=Foo.new "miao" => # >> f1 < f2 => true >> f1 >= f2 => false hope this helps