Search

Friends

Atomspheric CO2 (PPM)

Archives

Blather

Uptime verified by Wormly.com

31 May 2008

Sort by two object attributes in Ruby

This is a potentially ugly to solve, but you can actually compare two arrays. So it isn't so bad. If the first attributes are the same, it sorts by the second.

def <=>(other)
  [self.dtstart, self.dtend] <=> [other.dtstart, other.dtend]
end

Comments

  1. Hi Ryan,
    I cannot understand this at all. Nor can I understand why I can’t get to my footboot email with my usual password any more. What do I have to do?

    Stella / 10:26am / 10 June 2008

  2. Hi Stella. It should be working again now. I had changed the address because I’d been told I should, but as it turned out that was the wrong thing to do.

    Ryan / 10:43am / 10 June 2008

  3. Thanks Ryan. Problem solved!

    Stella / 10:16am / 11 June 2008

Leave a comment

Markdown

0.651 seconds