Skip to content

Instantly share code, notes, and snippets.

@miyohide
Created March 23, 2014 14:40
Show Gist options
  • Save miyohide/9723901 to your computer and use it in GitHub Desktop.
Save miyohide/9723901 to your computer and use it in GitHub Desktop.
version = "1.9.3-p123"
vers = version.tr("-p",".").split(".").delete_if { |i| i.size == 0 }.map { |i| i.to_i }
patch_level = vers.pop
sum = vers.each_with_index.map { |x, i| x.to_i * 10 ** (5 - i) }.inject { |sum,i| sum + i }
sum + patch_level # => 193123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment