Skip to content

Skip loading gem implementation on Ruby 4.0+#99

Open
hsbt wants to merge 1 commit intomasterfrom
skip-loading-gem-on-ruby-4
Open

Skip loading gem implementation on Ruby 4.0+#99
hsbt wants to merge 1 commit intomasterfrom
skip-loading-gem-on-ruby-4

Conversation

@hsbt
Copy link
Copy Markdown
Member

@hsbt hsbt commented Apr 7, 2026

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 if accept ruby/ruby#16358.

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>
Copilot AI review requested due to automatic review settings April 7, 2026 07:56
Copy link
Copy Markdown

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

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 Pathname constant and Kernel.Pathname on Ruby 4.x.
  • Only load the gem’s pathname.so / pathname_builtin implementation 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'
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants