Skip to content

Commit

Permalink
[rubygems/rubygems] Allow using Gem::Version without loading the re…
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed Dec 6, 2021
1 parent e41c195 commit d044ffd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/rubygems/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@
# 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__)

Expand Down
12 changes: 12 additions & 0 deletions test/rubygems/test_project_sanity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ def test_require_rubygems_package

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

0 comments on commit d044ffd

Please sign in to comment.