diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb index 3d0afa30947a..c732d7f968e1 100644 --- a/lib/rubygems/name_tuple.rb +++ b/lib/rubygems/name_tuple.rb @@ -89,9 +89,8 @@ def inspect # :nodoc: alias to_s inspect # :nodoc: def <=>(other) - [@name, @version, @platform == Gem::Platform::RUBY ? -1 : 1] <=> - [other.name, other.version, - other.platform == Gem::Platform::RUBY ? -1 : 1] + [@name, @version, Gem::Platform.sort_priority(@platform)] <=> + [other.name, other.version, Gem::Platform.sort_priority(other.platform)] end include Comparable diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 9750df181bce..4b8ac318479f 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -40,6 +40,10 @@ def self.match_gem?(platform, gem_name) match_platforms?(platform, Gem.platforms) end + def self.sort_priority(platform) + platform == Gem::Platform::RUBY ? -1 : 1 + end + def self.installable?(spec) if spec.respond_to? :installable_platform? spec.installable_platform? diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb index f4fee351a592..237bc3f782a0 100644 --- a/lib/rubygems/resolver/installer_set.rb +++ b/lib/rubygems/resolver/installer_set.rb @@ -71,7 +71,7 @@ def add_always_install(dependency) end found = found.sort_by do |s| - [s.version, s.platform == Gem::Platform::RUBY ? -1 : 1] + [s.version, Gem::Platform.sort_priority(s.platform)] end newest = found.last diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 83277fd281df..7ed963430f67 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -855,7 +855,7 @@ def self._resort!(specs) # :nodoc: next names if names.nonzero? versions = b.version <=> a.version next versions if versions.nonzero? - b.platform == Gem::Platform::RUBY ? -1 : 1 + Gem::Platform.sort_priority(b.platform) end end @@ -2333,7 +2333,7 @@ def satisfies_requirement?(dependency) # Returns an object you can use to sort specifications in #sort_by. def sort_obj - [@name, @version, @new_platform == Gem::Platform::RUBY ? -1 : 1] + [@name, @version, Gem::Platform.sort_priority(@new_platform)] end ##