Skip to content

Instantly share code, notes, and snippets.

@pjones
Created June 25, 2014 19:23
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 pjones/4054a1a4f3e3cd3c3f37 to your computer and use it in GitHub Desktop.
Save pjones/4054a1a4f3e3cd3c3f37 to your computer and use it in GitHub Desktop.
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