Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iNecas
Created December 27, 2010 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iNecas/756222 to your computer and use it in GitHub Desktop.
Save iNecas/756222 to your computer and use it in GitHub Desktop.
Ordering major.minor.revision version numbers
# wrong
["9.13.3", "9.3.2", "10.1.1", "9.3.5"].sort
# => ["10.1.1", "9.13.3", "9.3.2", "9.3.5"]
# right
["9.13.3", "9.3.2", "10.1.1", "9.3.5"].sort_by{|version| version.scan(/\d+/).map(&:to_i)}
# => ["9.3.2", "9.3.5", "9.13.3", "10.1.1"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment