RubyFlow The Ruby and Rails community linklog

Released the "sorting" gem

The “sorting” gem provides utilities to make sorting with ruby easier.

Installation gem install sorting

Usage require 'sorting/convenience' people.sort_by { |p| [desc(p.first_name), asc(p.age, :nils_last), asc { p.expensive }] }`

As you can see, it allows you to use sort_by to sort by ascending and descending values mixed, deal with potential nils, and performance optimization for expensive sort-values. You can find more examples on the github page.

Future I intend to add natural sorting (for which I already wrote plenty of code, the question is more how to fit it in best API-wise).

Feedback is very welcome!

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in