Skip to content

Workaround for directly loading Gem::Version#9268

Merged
hsbt merged 1 commit intomasterfrom
define-gem-module-version
Jan 28, 2026
Merged

Workaround for directly loading Gem::Version#9268
hsbt merged 1 commit intomasterfrom
define-gem-module-version

Conversation

@hsbt
Copy link
Copy Markdown
Member

@hsbt hsbt commented Jan 27, 2026

What was the end-user or developer problem that led to this PR?

If we use rubygems/version directlry without rubygems, we faced uninitialized constant Gem (NameError) error.

What is your fix for the problem, implemented in this PR?

Pick ruby/ruby@e410d93

Make sure the following tasks are checked

Copilot AI review requested due to automatic review settings January 27, 2026 08:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses an issue where directly loading rubygems/version without loading rubygems first results in an "uninitialized constant Gem (NameError)" error. The fix adds a workaround by ensuring the Gem module is defined before the Gem::Version class is declared.

Changes:

  • Added a module definition for Gem to prevent NameError when loading the version file directly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/rubygems/version.rb
# a zero to give a sensible result.

# Workaround for directly loading Gem::Version in some cases
module Gem; end
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining an empty module without checking if it already exists could override an existing Gem module definition. Consider using module Gem unless defined?(Gem); end or checking defined?(Gem) before defining to avoid potential issues.

Suggested change
module Gem; end
module Gem unless defined?(Gem); end

Copilot uses AI. Check for mistakes.
Comment thread lib/rubygems/version.rb
# For the last example, single-digit versions are automatically extended with
# a zero to give a sensible result.

# Workaround for directly loading Gem::Version in some cases
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment 'in some cases' is vague. Consider being more specific about when this workaround is needed, such as 'when requiring rubygems/version directly without requiring rubygems first'.

Suggested change
# Workaround for directly loading Gem::Version in some cases
# Workaround for directly loading Gem::Version when requiring rubygems/version
# directly without requiring rubygems first

Copilot uses AI. Check for mistakes.
@hsbt hsbt merged commit 7795149 into master Jan 28, 2026
101 of 103 checks passed
@hsbt hsbt deleted the define-gem-module-version branch January 28, 2026 22:36
hsbt added a commit that referenced this pull request Jan 28, 2026
Workaround for directly loading `Gem::Version`

(cherry picked from commit 7795149)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants