Class: Import_Module::Scope
- Defined in:
- lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb,
lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-pip.rb,
lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-hash.rb,
lib/carat-dev/import-module/import-module-0.81/lib/import-module-single-thread.rb,
lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-unbound-method.rb,
lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-unbound-method.rb
Overview
kk
Constant Summary collapse
- @@cm_no =
-1
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#updator ⇒ Object
readonly
Returns the value of attribute updator.
Class Method Summary collapse
Instance Method Summary collapse
- #activate ⇒ Object
-
#def_base_methods(meths) ⇒ Object
do not use (but faster).
- #forward_code(meths, mod) ⇒ Object
-
#initialize(target, source) ⇒ Scope
constructor
A new instance of Scope.
- #inspect ⇒ Object
- #pop ⇒ Object
- #push ⇒ Object
-
#set_meth_no ⇒ Object
private ### this declearation makes it slow.
- #set_methods ⇒ Object
Constructor Details
#initialize(target, source) ⇒ Scope
Returns a new instance of Scope.
117 118 119 120 121 122 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 117 def initialize(target, source) @target = target @klass = target.klass @source = source @mod = source.mod end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
102 103 104 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 102 def klass @klass end |
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
102 103 104 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 102 def mod @mod end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
102 103 104 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 102 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
102 103 104 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 102 def target @target end |
#updator ⇒ Object (readonly)
Returns the value of attribute updator.
8 9 10 |
# File 'lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-pip.rb', line 8 def updator @updator end |
Class Method Details
.create(klass, mod) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/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) ⇒ Object
113 114 115 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 113 def self.enclose(target, source) target.scopes[source.mod] ||= new(target, source) end |
Instance Method Details
#activate ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 124 def activate push begin yield ensure pop end end |
#def_base_methods(meths) ⇒ Object
do not use (but faster)
64 65 66 |
# File 'lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-pip.rb', line 64 def def_base_methods(meths)#do not use (but faster) BaseClass.class_eval *forward_code(meths, :orig) end |
#forward_code(meths, mod) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-pip.rb', line 49 def forward_code(meths, mod) s = "" line_no = __LINE__ + 6 meths.__each__ do |meth| meth0 = Import_Module.name(meth, @klass, false) meth1 = Import_Module.name(meth, mod) param = @source.param(meth) param0 = @source.param0(meth) s << "def #{meth0}(sender, #{param0})\n" s << " sender.#{meth1}(#{param})\n" s << "end\n" end [s, __FILE__, line_no] end |
#inspect ⇒ Object
142 143 144 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 142 def inspect "Scope(#{@target.inspect}, #{@source.inspect})" end |
#pop ⇒ Object
151 152 153 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 151 def pop Thread.current.__IMPORT_MODULE_PREFIX_stack.pop end |
#push ⇒ Object
146 147 148 149 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 146 def push() c = Thread.current.__IMPORT_MODULE_PREFIX_stack.current Thread.current.__IMPORT_MODULE_PREFIX_stack.push(update(c)) end |
#set_meth_no ⇒ Object
private ### this declearation makes it slow
157 158 159 160 161 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/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 ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb', line 133 def set_methods meths = @target.get_orig_methods(@source) @target.def_orig_methods(meths) set_meth_no def_methods mod = @mod @klass.class_eval do include mod end end |