module Import_Module::API

Public Instance Methods

adopt_module(mod) click to toggle source
# File lib/algebra/import-module.rb, line 71
def adopt_module(mod)
  # sw = Thread.critical or Thread.critical = true # this 'or' is safe
  unless scope = (@__IMPORT_MODULE_PREFIX_scopes ||= {})[mod.object_id]
    scope = Scope.create(self, mod)
    @__IMPORT_MODULE_PREFIX_scopes[mod.object_id] = scope
  end
  scope.push
  # Thread.critical = sw
  scope
end
import_module(mod) { || ... } click to toggle source
# File lib/algebra/import-module.rb, line 60
def import_module(mod)
  scope = adopt_module(mod) #not upper compatible
  if block_given?
    begin
      yield
    ensure
      scope.pop
    end
  end
end
set_orig_method(meth, orig) click to toggle source
# File lib/algebra/import-module.rb, line 82
def set_orig_method(meth, orig)
  meth = meth.id2name if meth.is_a? Symbol
  orig = orig.id2name if orig.is_a? Symbol
  meth0 = Import_Module.name(orig, :orig)
  module_eval "def #{meth}(*a, &b); #{meth0}(*a, &b); end\n"
end