Workaround for directly loading Gem::Version#9268
Conversation
There was a problem hiding this comment.
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
Gemto prevent NameError when loading the version file directly
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # a zero to give a sensible result. | ||
|
|
||
| # Workaround for directly loading Gem::Version in some cases | ||
| module Gem; end |
There was a problem hiding this comment.
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.
| module Gem; end | |
| module Gem unless defined?(Gem); end |
| # 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 |
There was a problem hiding this comment.
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'.
| # Workaround for directly loading Gem::Version in some cases | |
| # Workaround for directly loading Gem::Version when requiring rubygems/version | |
| # directly without requiring rubygems first |
Workaround for directly loading `Gem::Version` (cherry picked from commit 7795149)
What was the end-user or developer problem that led to this PR?
If we use
rubygems/versiondirectlry withoutrubygems, we faceduninitialized 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