module Sprockets::Utils

def module_include(base, mod)

Returns result of block.

mod - Module

Internal: Inject into target module for the duration of the block.
def module_include(base, mod)
  old_methods = {}
  mod.instance_methods.each do |sym|
    old_methods[sym] = base.instance_method(sym) if base.method_defined?(sym)
  end
  unless UNBOUND_METHODS_BIND_TO_ANY_OBJECT
    base.send(:include, mod) unless base < mod
  end
  mod.instance_methods.each do |sym|
    method = mod.instance_method(sym)
    base.send(:define_method, sym, method)
  end
  yield
ensure
  mod.instance_methods.each do |sym|
    base.send(:undef_method, sym) if base.method_defined?(sym)
  end
  old_methods.each do |sym, method|
    base.send(:define_method, sym, method)
  end
end