Created
November 19, 2010 17:41
-
-
Save leepa/706845 to your computer and use it in GitHub Desktop.
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
def normalize_version version, sep, max_width | |
version_split = version.split(sep) | |
output = "" | |
for s in version_split | |
output << sprintf('%' + max_width.to_s + 's', s) | |
end | |
output | |
end | |
v1 = '1.4.1' | |
v2 = '1.5' | |
v1_s = normalize_version v1, '.', 4 | |
v2_s = normalize_version v2, '.', 4 | |
cmp = v1_s <=> v2_s | |
# If cmp < 0 then v1 < v2 | |
# If cmp > 0 then v2 > v1 | |
# If cmp = 0 then v1 == v2 | |
puts "#{v1} #{(cmp < 0) ? "<" : cmp > 0 ? ">" : "=="} #{v2}" | |
v1 = '1.9.2-p149' | |
v2 = '1.9.2-p150' | |
cmp = v1_s <=> v2_s | |
# If cmp < 0 then v1 < v2 | |
# If cmp > 0 then v2 > v1 | |
# If cmp = 0 then v1 == v2 | |
puts "#{v1} #{(cmp < 0) ? "<" : cmp > 0 ? ">" : "=="} #{v2}" | |
v1 = '1.8.9-p149' | |
v2 = '1.9.2-p150' | |
cmp = v1_s <=> v2_s | |
# If cmp < 0 then v1 < v2 | |
# If cmp > 0 then v2 > v1 | |
# If cmp = 0 then v1 == v2 | |
puts "#{v1} #{(cmp < 0) ? "<" : cmp > 0 ? ">" : "=="} #{v2}" | |
v1 = 'R14B' | |
v2 = 'R15C' | |
cmp = v1_s <=> v2_s | |
# If cmp < 0 then v1 < v2 | |
# If cmp > 0 then v2 > v1 | |
# If cmp = 0 then v1 == v2 | |
puts "#{v1} #{(cmp < 0) ? "<" : cmp > 0 ? ">" : "=="} #{v2}" | |
v1 = 'R15C' | |
v2 = 'R14B' | |
cmp = v1_s <=> v2_s | |
# If cmp < 0 then v1 < v2 | |
# If cmp > 0 then v2 > v1 | |
# If cmp = 0 then v1 == v2 | |
puts "#{v1} #{(cmp < 0) ? "<" : cmp > 0 ? ">" : "=="} #{v2}" |
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
1.4.1 < 1.5 | |
1.9.2-p149 < 1.9.2-p150 | |
1.8.9-p149 < 1.9.2-p150 | |
R14B < R15C | |
R15C < R14B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment