Sha256: 92f70d02c65146474171af887411d963d58275a6bf7af7d6a45294bb82c6d6e0

Contents?: true

Size: 1.96 KB

Versions: 135

Compression:

Stored size: 1.96 KB

Contents

/**
 * Copyright 2005-2007 Ye Zheng
 * Distributed under the BSD License
 */

package com.xruby.runtime.lang;

public class RubySingletonClass extends RubyClass {

    private RubyValue owner_;

    public RubySingletonClass(RubyValue owner, RubyClass superclass, RubyModule scope) {
        super(null, superclass, scope);
        owner_ = owner;
        owner.setRubyClass(this);
        this.setInstanceVariable(owner, RubyID.attachedID);

        if (owner instanceof RubySingletonClass) {
            RubySingletonClass klass = (RubySingletonClass)owner;
            this.setRubyClass(this);
            RubyClass singletonsuper = klass.getSuperClass().getRealClass().getRubyClass();
            klass.setSuperClass(singletonsuper);
        } else {
            RubyClass metasuper = superclass.getRealClass().getRubyClass();
            if (metasuper != null) {
                this.setRubyClass(metasuper);
            }
        }
    }

    public RubyValue getConstant(String name) {
        RubyValue v = getOwnConstant(name);
        if (null != v) {
            return v;
        }

        if (owner_ instanceof RubyModule) {
            v = ((RubyModule)owner_).getConstant(name);
            if (null != v) {
                return v;
            }
        }

        //TODO this will call 'getOwnConstant' again, which is a waste of time
        return super.getConstant(name);
    }

    public RubyValue getClassVariable(String name) {
        if (owner_ instanceof RubyModule) {
            return ((RubyModule)owner_).getClassVariable(name);
        } else {
            return super.getClassVariable(name);
        }
    }

    public boolean isSingleton() {
        return true;
    }

    public boolean isRealClass() {
        return false;
    }

    public RubyValue allocObject(RubyBlock block) {
        throw new RubyException(RubyRuntime.TypeErrorClass, "can't create instance of virtual class");
    }
}

Version data entries

135 entries across 135 versions & 2 rubygems

Version Path
rhodes-2.2.3.beta.1 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.2 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.2.beta.1 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.1 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.1.beta.2 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.1.beta.1 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.0 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.0.beta.3 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.0.beta.2 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.2.0.beta.1 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.1.0 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.3 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.2 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.0 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.0.rc2 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.0.rc1 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.0.beta11 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.0.beta10 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.0.beta9 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java
rhodes-2.0.0.beta8 platform/shared/xruby/src/com/xruby/runtime/lang/RubySingletonClass.java