class Import_Module::Scope
kk
Attributes
klass[R]
mod[R]
source[R]
target[R]
Public Class Methods
create(klass, mod)
click to toggle source
# File lib/algebra/import-module.rb, line 105 def self.create(klass, mod) target = Target.enclose(klass) source = Source.enclose(mod) scope = enclose(target, source) scope.set_methods scope end
enclose(target, source)
click to toggle source
# File lib/algebra/import-module.rb, line 113 def self.enclose(target, source) target.scopes[source.mod] ||= new(target, source) end
new(target, source)
click to toggle source
# File lib/algebra/import-module.rb, line 117 def initialize(target, source) @target = target @klass = target.klass @source = source @mod = source.mod end
Public Instance Methods
activate() { || ... }
click to toggle source
# File lib/algebra/import-module.rb, line 124 def activate push begin yield ensure pop end end
inspect()
click to toggle source
# File lib/algebra/import-module.rb, line 142 def inspect "Scope(#{@target.inspect}, #{@source.inspect})" end
method_code(meth)
click to toggle source
# File lib/algebra/import-module.rb, line 182 def method_code(meth) param = @source.param(meth) no = @target.meth_no[meth] line_no = __LINE__ + 1 s = "def #{meth}(#{param})\n" s << " modid = Thread.current.__IMPORT_MODULE_PREFIX_proxy[#{no}]\n" i = 0 @target.scopes.each_key do |mod| s << (i == 0 ? " " : " els") << "if modid == #{mod.object_id}\n" s << " #{Import_Module.name(meth, mod)}(#{param})\n" i += 1 end s << " else\n" if i > 0 s << " #{Import_Module.name(meth, :orig)}(#{param})\n" s << " end\n" if i > 0 s << "end\n" s << "protected(:#{meth})\n" if @target.protecteds.include?(meth) s << "private(:#{meth})\n" if @target.privates.include?(meth) [s, __FILE__, line_no] end
pop()
click to toggle source
# File lib/algebra/import-module-single-thread.rb, line 19 def pop c = @target.stack.pop recov_methods(c) end
push()
click to toggle source
# File lib/algebra/import-module-single-thread.rb, line 13 def push def_methods c = @target.stack.current @target.stack.push(update(c)) end
set_meth_no()
click to toggle source
private ### this declearation makes it slow
# File lib/algebra/import-module.rb, line 157 def set_meth_no @source.methods.__each__ do |meth| @target.meth_no[meth] || @target.meth_no[meth] = (@@cm_no += 1) end end
set_methods()
click to toggle source
# File lib/algebra/import-module-single-thread.rb, line 5 def set_methods meths = @target.get_orig_methods(@source) @target.def_orig_methods meths # def_methods mod = @mod @klass.class_eval { include mod } end
Private Instance Methods
def_methods()
click to toggle source
# File lib/algebra/import-module-single-thread.rb, line 34 def def_methods mod = @mod target = @target @source.methods.__each__ do |meth| @klass.module_eval do alias_method meth, Import_Module.name(meth, mod) protected(meth) if target.protecteds.include?(meth) private(meth) if target.privates.include?(meth) end end end
recov_methods(c)
click to toggle source
# File lib/algebra/import-module-single-thread.rb, line 46 def recov_methods(c) orig_methods = @target.orig_methods d = @target.stack.current c.__each__ do |meth, _mod| @klass.module_eval do if m = d[meth] || orig_methods[meth] && :orig alias_method meth, Import_Module.name(meth, m) else undef_method meth end end end end
update(c)
click to toggle source
# File lib/algebra/import-module-single-thread.rb, line 26 def update(c) d = c.dup @source.methods.__each__ do |meth| d[meth] = @mod end d end