free_mutant/lib/mutant/require_highjack.rb
2015-11-15 23:13:43 +00:00

22 lines
476 B
Ruby

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.method(:require).tap do
target.module_eval do
define_method(:require, &callback)
public :require
end
end
end
end # RequireHighjack
end # Mutant