Skip to content
Fast sorting of version numbers
Branch: master
Clone or download
Latest commit 47b9f8c Feb 12, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
ext/version_sorter
script
test
vendor
.gitignore
.gitmodules
.readygo
.travis.yml
.vimrc
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
version_sorter.gemspec

README.md

Version sorter

Fast sorting of strings representing version numbers.

require 'version_sorter'

versions = ["1.0.9", "2.0", "1.0.10", "1.0.3", "2.0.pre"]

VersionSorter.sort(versions)
#=> 1.0.3
#=> 1.0.9
#=> 1.0.10
#=> 2.0.pre
#=> 2.0

You can also sort arrays of arbitrary objects by providing a block.

VersionSorter.sort(tags) { |tag| tag.name }

Library API:

VersionSorter.sort(versions)   #=> sorted array
VersionSorter.rsort(versions)  #=> reverse sorted array

VersionSorter.sort!(versions)  # sort array in place
VersionSorter.rsort!(versions) # reverse sort array in place

VersionSorter.compare(version_a, version_b) #=> positive or negative number depending on which way to sort 

http://github.com/blog/521-speedy-version-sorting

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.