Those solutions are definitely cool but I find James' to be more 
readable so that's what I'll use.

Robert Klemme wrote:
> require 'enumerator'
> 
> Foo = Struct.new :a,:b,:c,:d
> 
> class Foo
>   include Comparable
>   
>   def <=>(o)
>     members.inject(0) do |cmp,field|
>       return cmp unless cmp == 0
>       send(field) <=> o.send(field)
>     end
>   end
>   
>   # alternative
>   def <=>(o)
>     cmp = 0
>     each_pair do |field, val|
>       cmp = val <=> o.send(field)
>       return cmp unless cmp == 0
>     end
>     cmp
>   end
>   
>   # alternative
>   def <=>(o)
>     to_enum(:each_pair).inject(0) do |cmp,(field, val)|
>       cmp = val <=> o.send(field)
>       return cmp unless cmp == 0
>     end
>   end
> 
> end