Sorting an array of structs

Posted by keruilin on Stack Overflow See other posts from Stack Overflow or by keruilin
Published on 2010-05-19T23:20:48Z Indexed on 2010/05/19 23:30 UTC
Read the original article Hit count: 160

Filed under:
|
|
|

I have an array of structs called leaders. The struct class looks like this, for contextual info:

class Leader < Struct.new(:rank, :user); end

Two questions:

  1. How do I sort the array of structs by rank?
  2. How do I sort the array of structs by rank and by user.created_at?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about arrays