Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sort an array of strings with the same logic as `sort --dictionary-sort`
Ruby
Tag: v0.1.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
Gemfile
MIT-LICENSE
README.md
Rakefile
dictionary_order_sort.gemspec

README.md

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.

Installation

Add the following line to your Gemfile:

gem 'dictionary_order_sort'

Usage

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_"]
Something went wrong with that request. Please try again.