free_mutant/lib/mutant/require_highjack.rb
Markus Schirp 99ab9ff171 Change required Ruby version to >=2.3
* This commit does every 2.3 change required to get the build pass
* None of the changes can be extracted, without changing the build setup
2018-09-12 14:21:24 +00:00

27 lines
648 B
Ruby

# frozen_string_literal: true
module Mutant
# Require highjack
module RequireHighjack
# Install require callback
#
# @param [Module] target
# @param [#call] callback
#
# @return [#call]
# the original implementation on singleton
def self.call(target, callback)
target.public_method(:require).tap do
target.module_eval do
undef_method(:require)
define_method(:require, &callback)
class << self
undef_method(:require)
end
define_singleton_method(:require, &callback)
end
end
end
end # RequireHighjack
end # Mutant