Scott Kulik wrote:
> I can do sorting by a single field like the following:
>
> @users.sort! { |a,b| a.name.downcase < => b.name.downcase }
>
> but what if i want to sort by user.name and then user.rank?
>
> what's the best way to do this?
>
> thanks!
just got it:
@objects.sort! do |a,b|
comp = (b.rank <=> a.rank)
comp.zero? ? (b.position <=> a.position) : comp
end
in case anyone else needs help
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---