[前][次][番号順一覧][スレッド一覧]

ruby-changes:70079

From: David <ko1@a...>
Date: Mon, 6 Dec 2021 18:43:43 +0900 (JST)
Subject: [ruby-changes:70079] d044ffd77f (master): [rubygems/rubygems] Allow using `Gem::Version` without loading the rest of rubygems

https://git.ruby-lang.org/ruby.git/commit/?id=d044ffd77f

From d044ffd77fb3a486bbaca350980beee3f222bdb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Sun, 5 Dec 2021 09:23:28 +0100
Subject: [rubygems/rubygems] Allow using `Gem::Version` without loading the
 rest of rubygems

https://github.com/rubygems/rubygems/commit/1b862537a5
---
 lib/rubygems/version.rb              |  9 +++++++++
 test/rubygems/test_project_sanity.rb | 12 ++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb
index 20bbff4fdd5..37fd71edc06 100644
--- a/lib/rubygems/version.rb
+++ b/lib/rubygems/version.rb
@@ -149,6 +149,15 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/version.rb#L149
 # For the last example, single-digit versions are automatically extended with
 # a zero to give a sensible result.
 
+# Our code style opens classes directly without opening the intermediate
+# modules. This works because tha main entrypoint `rubygems.rb`, which defines
+# the root `Gem` module, is usually required first. But in this case we want to
+# allow using `Gem::Version` without loading the rest of rubygems, so we
+# explicit define the `Gem` placeholder module first.
+module Gem; end
+
+require_relative "deprecate"
+
 class Gem::Version
   autoload :Requirement, File.expand_path('requirement', __dir__)
 
diff --git a/test/rubygems/test_project_sanity.rb b/test/rubygems/test_project_sanity.rb
index 38c2541df6e..4324c997bdb 100644
--- a/test/rubygems/test_project_sanity.rb
+++ b/test/rubygems/test_project_sanity.rb
@@ -17,4 +17,16 @@ class TestProjectSanity < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_project_sanity.rb#L17
 
     assert status.success?, err
   end
+
+  def test_require_and_use_rubygems_version
+    err, status = Open3.capture2e(
+      *ruby_with_rubygems_in_load_path,
+      "--disable-gems",
+      "-rrubygems/version",
+      "-e",
+      "Gem::Version.new('2.7.0.preview1') >= Gem::Version.new(RUBY_VERSION)"
+    )
+
+    assert status.success?, err
+  end
 end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]