Last active
December 17, 2015 21:09
-
-
Save andrewvc/5672318 to your computer and use it in GitHub Desktop.
Sort version number strings properly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Turn version number into a 48 bit value (16 bits per version number) that is comparable to other versions | |
def rank_version(ver_str) | |
ver_str. | |
split('.'). | |
map(&:to_i). | |
reduce([5*16,0]) {|acc,v| #These vars are horribly named | |
i,a=acc | |
[i - 16, a | (v << i) ] | |
}[1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment