From 2432b3c7376961ce0c84a104bd2e0d3c7603b2dd Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 7 Apr 2026 15:35:20 +0900 Subject: [PATCH] Skip loading gem version of pathname on Ruby 4.0+ 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) --- lib/pathname.rb | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/lib/pathname.rb b/lib/pathname.rb index 37a5a21..84feeb7 100644 --- a/lib/pathname.rb +++ b/lib/pathname.rb @@ -10,28 +10,14 @@ # For documentation, see class Pathname. # -if defined?(::Pathname) # Clear builtin Pathname - # :stopdoc: - class ::Object - remove_const :Pathname - end +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' - $".delete('pathname.so') - # :startdoc: + require_relative 'pathname_builtin' end -require 'pathname.so' if RUBY_ENGINE == 'ruby' - -require_relative 'pathname_builtin' - class Pathname # * Find * # # Iterates over the directory tree in a depth first manner, yielding a