ruby-版本判断

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def compare_app_version(current, old)
return if current.blank? || old.blank?
la = current.split('.')
lb = old.split('.')
i = 0
if la.length > lb.length
len = la.length
else
len = lb.length
end
while i <= len do
if (la[i] && !lb[i] && la[i].to_i > 0) || (la[i].to_i > lb[i].to_i)
return 1
elsif (lb[i] && !la[i] && lb[i].to_i > 0) || (la[i].to_i < lb[i].to_i)
return -1
end
i +=1
end
return 0
end