Created
June 25, 2014 19:23
-
-
Save pjones/4054a1a4f3e3cd3c3f37 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
class Version | |
attr_reader(:major, :minor, :patch) | |
def initialize (version) | |
@major, @minor, @patch = | |
version.split('.').map(&:to_i) | |
end | |
def <=> (other) | |
return nil unless other.is_a?(Version) | |
[ major <=> other.major, | |
minor <=> other.minor, | |
patch <=> other.patch, | |
].detect {|n| !n.zero?} || 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment