Module: Mutant::RequireHighjack Private

Defined in:
lib/mutant/require_highjack.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Require highjack

Class Method Summary collapse

Class Method Details

.call(target, callback) ⇒ #call

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Install require callback

Parameters:

  • target (Module)
  • callback (#call)

Returns:

  • (#call)

    the original implementation on singleton



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mutant/require_highjack.rb', line 14

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