/** 
 * Copyright 2005-2007 Ye Zheng
 * Distributed under the GNU General Public License 2.0
 */

package com.xruby.runtime.lang;

public class RubySingletonClass extends RubyClass {
    public RubySingletonClass(RubyValue obj, RubyClass superclass) {
        super(null, superclass, null);
        obj.setRubyClass(this);
        this.setInstanceVariable(obj, CommonRubyID.attachedID);

        if (obj instanceof RubySingletonClass) {
            RubySingletonClass klass = (RubySingletonClass)obj;
            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 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");
	}
}

@@ -1,12 +1,11 @@
 /**
- 
 %0D%0A * Cop
@@ -179,24 +179,59 @@
 ubyClass %7B%0D%0A
+%0D%0A    private RubyValue owner_;%0D%0A%0D%0A
     public R
@@ -324,24 +324,47 @@
 ss, null);%0D%0A
+        owner_ = obj;%0D%0A
         obj.
@@ -958,25 +958,517 @@
 %7D%0D%0A    %7D%0D%0A%0D%0A
-%09
+    public RubyValue getConstant(String name) %7B%0D%0A        if (owner_ instanceof RubyModule) %7B%0D%0A            return ((RubyModule)owner_).getConstant(name);%0D%0A        %7D else %7B%0D%0A            return super.getConstant(name);%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    public RubyValue getClassVariable(String name) %7B%0D%0A        if (owner_ instanceof RubyModule) %7B%0D%0A            return ((RubyModule)owner_).getClassVariable(name);%0D%0A        %7D else %7B%0D%0A            return super.getClassVariable(name);%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    
 public boole
@@ -1483,26 +1483,32 @@
 gleton() %7B%0D%0A
-%09%09
+        
 return true;
@@ -1505,31 +1505,37 @@
 turn true;%0D%0A
-%09
+    
 %7D%0D%0A%0D%0A
-%09
+    
 public boole
@@ -1554,18 +1554,24 @@
 ss() %7B%0D%0A
-%09%09
+        
 return f
@@ -1581,15 +1581,21 @@
 e;%0D%0A
-%09
+    
 %7D%0D%0A%0D%0A
-%09
+    
 publ
@@ -1643,10 +1643,16 @@
  %7B%0D%0A
-%09%09
+        
 thro
@@ -1747,9 +1747,12 @@
 );%0D%0A
-%09
+    
 %7D%0D%0A%7D

fix broken test