Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (16 sloc) 960 Bytes

Dictionary Order Sort

Build Status

Sorts an array of strings in the same manner as the Linux sort command running with the --dictionary-order option. Only blanks and alphanumeric characters are considered.

I created this gem because I needed to use the comm command in a Capistrano recipe, and wanted to sort the list of files in Ruby. comm requires the input files to be sorted using the collating sequence specified by `LC_COLLATE', and this defaults to dictionary sort.


Add the following line to your Gemfile:

gem 'dictionary_order_sort'


You can now use the dict_sort method on arrays or sets. Array elements must be strings, or respond to to_s.

Use it like this:

["a", "a-2", "_a-3", "abc_", "_def_"].dict_sort

#=> ["a", "a-2", "_a-3", "abc_", "_def_"]