Skip to content

Commit

Permalink
Improve the Kernel#require patch to avoid warnings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
byroot committed Dec 14, 2023
1 parent 5edf266 commit 83d5c74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
8 changes: 5 additions & 3 deletions lib/bootsnap/load_path_cache/core_ext/kernel_require.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -34,4 +34,6 @@ def require(path)
return ret
end
end

private :require
end

0 comments on commit 83d5c74

Please sign in to comment.