From: Marnen Laibow-Koser Date: 2009-11-17T22:58:06+09:00 Subject: Re: Newbie question: Defining a numeric type Brian Candler wrote: > Brian Candler wrote: >> You can still make the character objects be Comparable, if normally you >> want to order them by level. > > ... and in this case it probably makes sense to have a to_i method. > > class Character > def to_i > level > end > > include Comparable > def <=>(other) > to_i <=> other.to_i > end > end > > This allows you to say not only: > > if ogre > elf > > but also: > > if ogre > 12 > > which I imagine would be useful. I don't know about you, but I'd find this confusing. A character is not its level, and I think if ogre < 12 is actually harder to understand than if ogre.level < 12 Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.