RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  
 

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!

Comments

Post a Comment

Comment abilities for non registered users are currently deactivated, pending time to add a proper CAPTCHA to solve the escalating spam problem. Sorry!