From: Eero Saynatkari Date: 2005-12-12T06:43:52+09:00 Subject: Re: creating a <=> method Dirk Meijer wrote: > 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. # The spaceship operator needs to return either # -1, 0 or 1 depending on whether it is 'smaller', # 'equal' or 'greater' than the other object. def <=>(other) # We can use String#<=> here if both are Strings. # Otherwise implement some custom comparison as above. @my_value.to_s <=> other.to_s end > greetings, Dirk. E -- Posted via http://www.ruby-forum.com/.