From 9828502570acce53f4094c23756bc82bd256eab7 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Tue, 11 Jan 2022 05:30:05 +0900 Subject: [rubygems/rubygems] Let Version#spaceship accept a String With this patch, handwriting version comparisons become a little bit easier. before: SomeGem.version <=> Gem::Version.new('1.3') after: SomeGem.version <=> '1.3' https://github.com/rubygems/rubygems/commit/7e0dbb79f2 --- lib/rubygems/version.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index 42e0f23505..9a26f721d6 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -341,9 +341,11 @@ class Gem::Version # 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 return +nil+. + # Gem::Version or a valid version String return +nil+. 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 -- cgit v1.2.3