Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Gem::Version#<=>
(untyped other) -> ::Integer?
<=>(other)
lib/rubygems/version.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/rubygems/version.rb, line 360
def <=>(other)
return self <=> self.class.new(other) if (String === other) && self.class.correct?(other)
return unless Gem::Version === other
return 0 if @version == other.version || canonical_segments == other.canonical_segments
lhsegments = canonical_segments
rhsegments = other.canonical_segments
lhsize = lhsegments.size
rhsize = rhsegments.size
limit = (lhsize > rhsize ? lhsize : rhsize) - 1
i = 0
while i <= limit
lhs = lhsegments[i] || 0
rhs = rhsegments[i] || 0
i += 1
next if lhs == rhs
return -1 if String === lhs && Numeric === rhs
return 1 if Numeric === lhs && String === rhs
return lhs <=> rhs
end
0
end
Compares this version with other returning -1, 0, or 1 if the other version is larger, the same, or smaller than this one. Attempts to compare to something that’s not a Gem::Version or a valid version String return nil.
See also
.nil_versions_are_discouraged!
#approximate_recommendation
.new
#bump
also in
4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0