From: "marcandre (Marc-Andre Lafortune)" Date: 2013-05-18T23:31:26+09:00 Subject: [ruby-core:55050] [ruby-trunk - Feature #8422] add Enumerable#reverse_sort and Enumerable#reverse_sort_by Issue #8422 has been updated by marcandre (Marc-Andre Lafortune). matz (Yukihiro Matsumoto) wrote: > It can be done by a.sort{|a,b| b<=>a}. That will typically be much slower though. Currently, the best way to do a reverse sort, performance-wise, is `a.sort.reverse!` For a random 100 number array, for example: sort.reverse! is faster than sort.reverse by 10% �� 1.0% sort.reverse is faster than sort_by by 6x �� 0.1 sort_by is faster than sort by 60% �� 1.0% Code: https://gist.github.com/marcandre/5604592 ---------------------------------------- Feature #8422: add Enumerable#reverse_sort and Enumerable#reverse_sort_by https://bugs.ruby-lang.org/issues/8422#change-39424 Author: Hanmac (Hans Mackowiak) Status: Feedback Priority: Normal Assignee: Category: Target version: they are better when you want descending order, enum.sort.reverse does work too, but it is to slow because it needs to build that result array twice they both can be defined just like #sort and #sort_by but negates the result of the compare block -- http://bugs.ruby-lang.org/