How can I sort multiple objects by a secondary key when the first one is equal?
In my Book class I have the following method used for sorting
def <=>(other)
printed_on <=> other.printed_on
end
Now I need the books printed the same day (printed_on = other.printed_on) to be sorded by page_number.
Since with sort_by you can pass an array of keys, I have tried
def <=>(other)
[printed_on <=> other.printed_on, page_number <=> other.page_number]
end
but I get
undefined method `>' for [1, 1]:Array