From: Cameron McBride Date: 2006-03-10T01:18:03+09:00 Subject: Re: nuby question: sorting with nils On 3/9/06, Toby DiPasquale wrote: > Speaking of this very topic, I am having an issue where I want to sort > objects by two of its attributes in a SortedSet, but its not working > out: > > I'd like it to be sorted first by its :a attribute, but if they are > equal, by whatever sorting on the :b attributes comes up with. as a quick alternative, sorting by several attributes is pretty easy using #sort_by X = Struct.new :a, :b s = [] s << X.new(3, 3) s << X.new(3, 4) s << X.new(1, 2) s << X.new(4, 8) s << X.new(4, 2) sorted = s.sort_by { |a| [a.a,a.b] } sorted.each { |v| p v } # # # # # Cameron