Skip to content

Instantly share code, notes, and snippets.

@pjones
Created Jun 25, 2014
Embed
What would you like to do?
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