Skip to content

Commit

Permalink
Merge pull request #462 from Shopify/fix-require-warning
Browse files Browse the repository at this point in the history
Improve the `Kernel#require` patch to avoid warnings
  • Loading branch information
casperisfine authored Dec 14, 2023
2 parents bbdf48b + 83d5c74 commit 8fbb1ce
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 8fbb1ce

Please sign in to comment.