Created
September 18, 2016 05:37
-
-
Save shotat/337f622dabef2137eecea3c71eac7964 to your computer and use it in GitHub Desktop.
Version.rb
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 | |
include(Compareble) | |
attr_accessor(: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