Add Version#compare

This commit is contained in:
Douglas Eichelberger 2023-04-04 17:53:51 -07:00
parent 41e7ee7b51
commit 0ca4f7eebb

View File

@ -532,6 +532,19 @@ class Version
false
end
sig { params(comparator: String, other: Version).returns(T::Boolean) }
def compare(comparator, other)
case comparator
when ">=" then self >= other
when ">" then self > other
when "<" then self < other
when "<=" then self <= other
when "==" then self == other
when "!=" then self != other
else raise ArgumentError, "Unknown comparator: #{comparator}"
end
end
sig { params(other: T.untyped).returns(T.nilable(Integer)) }
def <=>(other)
# Needed to retain API compatibility with older string comparisons