Skip to content

Instantly share code, notes, and snippets.

@shotat
Created September 18, 2016 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shotat/337f622dabef2137eecea3c71eac7964 to your computer and use it in GitHub Desktop.
Save shotat/337f622dabef2137eecea3c71eac7964 to your computer and use it in GitHub Desktop.
Version.rb
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