diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index 625de73440..65cbb679af 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -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