Lines Matching refs:cref

267   function handle_autoload(cref, name) {  argument
268 if (!cref.$$autoload[name].loaded) {
269 cref.$$autoload[name].loaded = true;
271 Opal.Kernel.$require(cref.$$autoload[name].path);
273 cref.$$autoload[name].exception = e;
276 cref.$$autoload[name].required = true;
277 if (cref.$$const[name] != null) {
278 cref.$$autoload[name].success = true;
279 return cref.$$const[name];
281 } else if (cref.$$autoload[name].loaded && !cref.$$autoload[name].required) {
282 if (cref.$$autoload[name].exception) { throw cref.$$autoload[name].exception; }
294 // - constant reference (cref): the module/class that acts as a namespace
298 // Get the constant in the scope of the current cref
299 function const_get_name(cref, name) { argument
300 if (cref) {
301 if (cref.$$const[name] != null) { return cref.$$const[name]; }
302 if (cref.$$autoload && cref.$$autoload[name]) {
303 return handle_autoload(cref, name);
327 function const_lookup_ancestors(cref, name) { argument
330 if (cref == null) return;
332 ancestors = $ancestors(cref);
344 // but only if cref is missing or a module.
345 function const_lookup_Object(cref, name) { argument
346 if (cref == null || cref.$$is_module) {
352 function const_missing(cref, name) { argument
353 return (cref || _Object).$const_missing(name);
356 // Look for the constant just in the current cref or call `#const_missing`
357 Opal.const_get_local = function(cref, name, skip_missing) { argument
360 if (cref == null) return;
362 if (cref === '::') cref = _Object;
364 if (!cref.$$is_module && !cref.$$is_class) {
365 $raise(Opal.TypeError, cref.toString() + " is not a class/module");
368 result = const_get_name(cref, name);
369 return result != null || skip_missing ? result : const_missing(cref, name);
372 // Look for the constant relative to a cref or call `#const_missing` (when the
374 Opal.const_get_qualified = function(cref, name, skip_missing) { argument
379 result = const_get_name(_Object, cref);
382 return Opal.const_get_qualified(_Object, cref, skip_missing);
385 if (cref == null) return;
387 if (cref === '::') cref = _Object;
389 if (!cref.$$is_module && !cref.$$is_class) {
390 $raise(Opal.TypeError, cref.toString() + " is not a class/module");
393 if ((cache = cref.$$const_cache) == null) {
394 $prop(cref, '$$const_cache', Object.create(null));
395 cache = cref.$$const_cache;
400 ((result = const_get_name(cref, name)) != null) ||
401 ((result = const_lookup_ancestors(cref, name)) != null);
407 return result != null || skip_missing ? result : const_missing(cref, name);
414 // cref ancestors or call `#const_missing` (when the constant has no :: prefix).
416 var cref = nesting[0], result, current_version = Opal.const_cache_version, cache, cached;
425 ((result = const_get_name(cref, name)) != null) ||
427 ((result = const_lookup_ancestors(cref, name)) != null) ||
428 ((result = const_lookup_Object(cref, name)) != null);
435 return result != null || skip_missing ? result : const_missing(cref, name);
438 // Register the constant on a cref and opportunistically set the name of
440 function $const_set(cref, name, value) { argument
443 if (cref == null || cref === '::') cref = _Object;
447 if (value.$$base_module == null) value.$$base_module = cref;
450 cref.$$const = (cref.$$const || Object.create(null));
452 if (name in cref.$$const || ("$$autoload" in cref && name in cref.$$autoload)) {
456 cref.$$const[name] = value;
461 cref.$$ = cref.$$const;
466 if (cref === _Object) Opal[name] = value;
469 $prop(cref, name, value);
471 if (new_const && cref.$const_added && !cref.$const_added.$$pristine) {
472 cref.$const_added(name);
479 // Get all the constants reachable from a given cref, by default will include
481 Opal.constants = function(cref, inherit) { argument
484 var module, modules = [cref], i, ii, constants = {}, constant;
486 if (inherit) modules = modules.concat($ancestors(cref));
487 …if (inherit && cref.$$is_module) modules = modules.concat([Opal.Object]).concat($ancestors(Opal.Ob…
493 if (cref !== _Object && module == _Object) break;
508 // Remove a constant from a cref.
509 Opal.const_remove = function(cref, name) { argument
512 if (cref.$$const[name] != null) {
513 var old = cref.$$const[name];
514 delete cref.$$const[name];
518 if (cref.$$autoload && cref.$$autoload[name]) {
519 delete cref.$$autoload[name];
523 $raise(Opal.NameError, "constant "+cref+"::"+cref.$name()+" not defined");