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. If you want "if 12 < ogre" as well,
then:
class Character
def coerce(other)
[other, to_i]
end
end
--
Posted via http://www.ruby-forum.com/.