Class: VersionString
- Inherits:
-
String
- Object
- String
- VersionString
- Defined in:
- lib/version_string.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.make_comparable(s1, s2) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/version_string.rb', line 15 def self.make_comparable(s1, s2) a1 = s1.split(".").map(&:to_i) a2 = s2.split(".").map(&:to_i) len1, len2 = a1.length, a2.length if len1 < len2 a1.concat([0] * (len2 - len1)) elsif len1 > len2 a2.concat([0] * (len1 - len2)) end [a1, a2] end |
Instance Method Details
#<=>(other) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/version_string.rb', line 3 def <=>(other) a1, a2 = self.class.make_comparable(self, other) a1.zip(a2).each do |pair| if pair[0] < pair[1] return -1 elsif pair[0] > pair[1] return 1 end end 0 end |