File tree 3 files changed +25
-0
lines changed
3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 15
15
16
16
* Remove ` const_missing ` option from compiler. All constant lookups are now strict.
17
17
18
+ * Add initial support for Module#autoload.
19
+
18
20
## 0.6.2 2014-04-25
19
21
20
22
* Added Range#size
Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ def compile_default?
126
126
127
127
add_special :autoload do
128
128
if scope . class_scope?
129
+ compile_default!
129
130
str = DependencyResolver . new ( compiler , arglist [ 2 ] ) . resolve
130
131
compiler . requires << str unless str . nil?
131
132
push fragment ( '' )
Original file line number Diff line number Diff line change @@ -180,6 +180,19 @@ def attr_writer(*names)
180
180
181
181
alias attr attr_accessor
182
182
183
+ def autoload ( const , path )
184
+ %x{
185
+ var autoloaders;
186
+
187
+ if (!(autoloaders = self.__autoload)) {
188
+ autoloaders = self.__autoload = {};
189
+ }
190
+
191
+ autoloaders[#{ const } ] = #{ path } ;
192
+ return nil;
193
+ }
194
+ end
195
+
183
196
def constants
184
197
`self._scope.constants`
185
198
end
@@ -233,6 +246,15 @@ def const_get(name, inherit = true)
233
246
end
234
247
235
248
def const_missing ( const )
249
+ %x{
250
+ var autoloader;
251
+
252
+ if (self.__autoload && (autoloader = self.__autoload[#{ const } ])) {
253
+ console.log("autoloading: " + #{ const } );
254
+ return self.$require(autoloader);
255
+ }
256
+ }
257
+
236
258
name = `self._name`
237
259
238
260
raise NameError , "uninitialized constant #{ name } ::#{ const } "
You can’t perform that action at this time.
0 commit comments