TryResolveConstant() private method

private TryResolveConstant ( RubyContext callerContext, RubyGlobalScope autoloadScope, string name, IronRuby.Runtime.ConstantStorage &value ) : bool
callerContext RubyContext
autoloadScope IronRuby.Runtime.RubyGlobalScope
name string
value IronRuby.Runtime.ConstantStorage
return bool
Exemplo n.º 1
0
        internal static RubyClass/*!*/ DefineClass(Scope/*!*/ autoloadScope, RubyModule/*!*/ owner, string/*!*/ name, object superClassObject) {
            Assert.NotNull(owner);
            RubyClass superClass = ToSuperClass(owner.Context, superClassObject);

            object existing;
            if (ReferenceEquals(owner, owner.Context.ObjectClass)
                ? owner.TryResolveConstant(autoloadScope, name, out existing)
                : owner.TryGetConstant(autoloadScope, name, out existing)) {
                
                RubyClass cls = existing as RubyClass;
                if (cls == null || !cls.IsClass) {
                    throw RubyExceptions.CreateTypeError(String.Format("{0} is not a class", name));
                }

                if (superClassObject != null && !ReferenceEquals(cls.SuperClass, superClass)) {
                    throw RubyExceptions.CreateTypeError(String.Format("superclass mismatch for class {0}", name));
                }
                return cls;
            } else {
                return owner.Context.DefineClass(owner, name, superClass);
            }
        }
Exemplo n.º 2
0
        public static object GetConstant(RubyScope/*!*/ scope, RubyModule/*!*/ owner, string/*!*/ name, bool lookupObject) {
            Assert.NotNull(scope, owner, name);

            object result;
            if (owner.TryResolveConstant(scope.GlobalScope, name, out result)) {
                return result;
            }

            RubyClass objectClass = owner.Context.ObjectClass;
            if (owner != objectClass && lookupObject && objectClass.TryResolveConstant(scope.GlobalScope, name, out result)) {
                return result;
            }

            CheckConstantName(name);
            return RubySites.ModuleConstMissing(scope.RubyContext, owner, name);
        }