free_mutant/lib/mutant/require_highjack.rb

23 lines
476 B
Ruby
Raw Normal View History

2014-04-04 08:38:06 -04:00
module Mutant
# Require highjack
module RequireHighjack
2014-04-04 08:38:06 -04:00
# Install require callback
2014-04-04 08:38:06 -04:00
#
# @param [Module] target
# @param [#call] callback
2014-04-04 08:38:06 -04:00
#
# @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
2014-04-04 08:38:06 -04:00
end
end
end
end # RequireHighjack
end # Mutant