free_mutant/lib/mutant/require_highjack.rb
2015-07-02 03:35:54 +00:00

24 lines
501 B
Ruby

module Mutant
# Require highjack
module RequireHighjack
# Install require callback
#
# @param [Module] target
# @param [#call] callback
#
# @return [#call]
# the original implementation on singleton
#
# @api private
def self.call(target, callback)
target.method(:require).tap do
target.module_eval do
define_method(:require, &callback)
public :require
end
end
end
end # RequireHighjack
end # Mutant