Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Last active December 17, 2015 21:09
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 andrewvc/5672318 to your computer and use it in GitHub Desktop.
Save andrewvc/5672318 to your computer and use it in GitHub Desktop.
Sort version number strings properly
# 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