Module: RuboCop::Shopify::GemVersionStringComparableBackport

Defined in:
lib/rubocop/shopify/gem_version_string_comparable_backport.rb

Overview

Backport rubygems/rubygems#5275, so we can compare ‘Gem::Version`s directly against `String`s.

Gem::Version.new("1.2.3") > "1.2"

Without this, to support Ruby < 3.2, we would have to create a new ‘Gem::Version` instance ourselves.

Gem::Version.new("1.2.3") > Gem::Version.new("1.2")

This would get very verbose in our RuboCop config files.

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



19
20
21
22
23
# File 'lib/rubocop/shopify/gem_version_string_comparable_backport.rb', line 19

def <=>(other)
  return self <=> self.class.new(other) if (String === other) && self.class.correct?(other)

  super
end