Open
Conversation
Ruby 4.0 makes Pathname a built-in class, and Ruby 4.1 will make all methods including find, rmtree, and mktmpdir built-in as well. On Ruby 4.0, only the three additional methods are redefined from the gem. On Ruby 4.1+, the gem returns immediately and defers entirely to the built-in implementation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adjusts pathname gem loading behavior for Ruby 4.x now that Pathname is built into Ruby, and aims to fully defer to the built-in implementation on Ruby 4.1+.
Changes:
- Add a Ruby version guard intended to skip gem loading on Ruby >= 4.1.
- Avoid clearing/removing the built-in
Pathnameconstant andKernel.Pathnameon Ruby 4.x. - Only load the gem’s
pathname.so/pathname_builtinimplementation on Ruby < 4.0.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+13
to
+16
| return if RUBY_VERSION >= '4.1' | ||
|
|
||
| # Remove module_function Pathname | ||
| class << ::Kernel | ||
| undef Pathname | ||
| end | ||
| module ::Kernel | ||
| undef Pathname | ||
| end | ||
| unless RUBY_VERSION >= '4' | ||
| require 'pathname.so' if RUBY_ENGINE == 'ruby' |
There was a problem hiding this comment.
Using return at the top level of a required file will raise LocalJumpError: unexpected return (i.e., the file won’t load). To make the file a no-op on Ruby >= 4.1, wrap the remainder of the file in a version guard (e.g., if RUBY_VERSION < '4.1' ... end) instead of using return.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ruby 4.0 makes Pathname a built-in class, and Ruby 4.1 will make all methods including
find,rmtree, andmktmpdirbuilt-in as well.On Ruby 4.0, only the three additional methods are redefined from the gem. On Ruby 4.1+, the gem returns immediately and defers entirely to the built-in implementation if accept ruby/ruby#16358.