[ruby/rubygems] Undeprecate Gem::Version#<=> against strings

This pattern is extremely common across the ecosystem, I don't think
it's reasonable to deprecate it.

I understand the performance argument, but perhaps the dependency
resolution algorithm can use another method that is private API
and only works with two `Version` instance.

https://github.com/ruby/rubygems/commit/024b4b547a
This commit is contained in:
Jean Boussier 2025-11-21 19:30:04 +01:00 committed by git
parent 6e2906f60d
commit 2289961b48
2 changed files with 1 additions and 8 deletions

View File

@ -344,9 +344,6 @@ class Gem::Version
def <=>(other)
if String === other
unless Gem::Deprecate.skip
warn "comparing version objects with strings is deprecated and will be removed", uplevel: 1
end
return unless self.class.correct?(other)
return self <=> self.class.new(other)
end

View File

@ -160,11 +160,7 @@ class TestGemVersion < Gem::TestCase
[-1, "1.9.3.1"],
[nil, "whatever"],
].each do |cmp, string_ver|
actual_stdout, actual_stderr = capture_output do
assert_equal(cmp, v("1.9.3") <=> string_ver)
end
assert_empty actual_stdout
assert_match(/comparing version objects with strings is deprecated and will be removed/, actual_stderr)
assert_equal(cmp, v("1.9.3") <=> string_ver)
end
end