Skip to content

Commit d044ffd

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[rubygems/rubygems] Allow using Gem::Version without loading the rest of rubygems
rubygems/rubygems@1b862537a5
1 parent e41c195 commit d044ffd

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/rubygems/version.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@
149149
# For the last example, single-digit versions are automatically extended with
150150
# a zero to give a sensible result.
151151

152+
# Our code style opens classes directly without opening the intermediate
153+
# modules. This works because tha main entrypoint `rubygems.rb`, which defines
154+
# the root `Gem` module, is usually required first. But in this case we want to
155+
# allow using `Gem::Version` without loading the rest of rubygems, so we
156+
# explicit define the `Gem` placeholder module first.
157+
module Gem; end
158+
159+
require_relative "deprecate"
160+
152161
class Gem::Version
153162
autoload :Requirement, File.expand_path('requirement', __dir__)
154163

test/rubygems/test_project_sanity.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,16 @@ def test_require_rubygems_package
1717

1818
assert status.success?, err
1919
end
20+
21+
def test_require_and_use_rubygems_version
22+
err, status = Open3.capture2e(
23+
*ruby_with_rubygems_in_load_path,
24+
"--disable-gems",
25+
"-rrubygems/version",
26+
"-e",
27+
"Gem::Version.new('2.7.0.preview1') >= Gem::Version.new(RUBY_VERSION)"
28+
)
29+
30+
assert status.success?, err
31+
end
2032
end

0 commit comments

Comments
 (0)