Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created February 3, 2014 21:08
Show Gist options
  • Save jonelf/8792448 to your computer and use it in GitHub Desktop.
Save jonelf/8792448 to your computer and use it in GitHub Desktop.
Generic sort order.
sort_order = {"C" => 1, "Y" => 2, "M" => 3}
test_arr = ["M", "C", "Y"]
sorted = test_arr.sort_by {|c| sort_order[c]}
# => ["C", "Y", "M"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment