Did you consider using sort to order these?

http://www.ruby-doc.org/core-2.1.0/Array.html#method-i-sort