Skip to content

Commit 83d5c74

Browse files
committed
Improve the Kernel#require patch to avoid warnings
Fix: #461 Also neither Rubygems nor Zeitwerk bother decorating `Kernel.require`, and no-one requires with `Kernel.require` so likely not worth it, and if anything that offers an escape hatch to bypass Bootsnap.
1 parent 5edf266 commit 83d5c74

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
* Improved the `Kernel#require` decorator to not cause a method redefinition warning. See #461.
4+
35
# 1.17.0
46

57
* Ensure `$LOAD_PATH.dup` is Ractor shareable to fix an conflict with `did_you_mean`.

lib/bootsnap/load_path_cache/core_ext/kernel_require.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# frozen_string_literal: true
22

33
module Kernel
4-
module_function
4+
alias_method :require_without_bootsnap, :require
55

6-
alias_method(:require_without_bootsnap, :require)
6+
alias_method :require, :require # Avoid method redefinition warnings
77

8-
def require(path)
8+
def require(path) # rubocop:disable Lint/DuplicateMethods
99
return require_without_bootsnap(path) unless Bootsnap::LoadPathCache.enabled?
1010

1111
string_path = Bootsnap.rb_get_path(path)
@@ -34,4 +34,6 @@ def require(path)
3434
return ret
3535
end
3636
end
37+
38+
private :require
3739
end

0 commit comments

Comments
 (0)