Add Version#compare
This commit is contained in:
parent
41e7ee7b51
commit
0ca4f7eebb
@ -532,6 +532,19 @@ class Version
|
|||||||
false
|
false
|
||||||
end
|
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)) }
|
sig { params(other: T.untyped).returns(T.nilable(Integer)) }
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
# Needed to retain API compatibility with older string comparisons
|
# Needed to retain API compatibility with older string comparisons
|
||||||
|
Loading…
x
Reference in New Issue
Block a user