diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8f1ce..6166163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +* Improved the `Kernel#require` decorator to not cause a method redefinition warning. See #461. + # 1.17.0 * Ensure `$LOAD_PATH.dup` is Ractor shareable to fix an conflict with `did_you_mean`. diff --git a/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb b/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb index 034a1ff..33540ba 100644 --- a/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb +++ b/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true module Kernel - module_function + alias_method :require_without_bootsnap, :require - alias_method(:require_without_bootsnap, :require) + alias_method :require, :require # Avoid method redefinition warnings - def require(path) + def require(path) # rubocop:disable Lint/DuplicateMethods return require_without_bootsnap(path) unless Bootsnap::LoadPathCache.enabled? string_path = Bootsnap.rb_get_path(path) @@ -34,4 +34,6 @@ def require(path) return ret end end + + private :require end