Am 17.06.2013 17:56, schrieb Joel Pearson:
> You can define the method <=> to allow comparison between objects.
[...]
> or maybe something like this?
>
> def <=> other
>    ( bar + baz ) <=> ( other.bar + other.baz )
> end

That's probably not what the OP wants. It would return true for

   lorem.bar = 1
   lorem.baz = 2

   ipsum.bar = 2
   ipsum.baz = 1

The <=> operator is useful for objects that have a natural ordering.
This might not make sense here. (What would be the natural, distinct
ordering of songs with a `title` and an `artist`? Which attribute
should have higher priority?...)

To test for equality of all attributes, you could simply do

   def ==(other)
     bar == other.bar && baz == other.baz
   end

(This will work fine as long as you only compare objects of the
same class.)


-- 
<https://github.com/stomar/>