package com.xruby.runtime.builtin;

import com.xruby.runtime.lang.RubyClass;
import com.xruby.runtime.lang.RubyException;
import com.xruby.runtime.lang.RubyModule;
import com.xruby.runtime.lang.RubyRuntime;
import com.xruby.runtime.lang.RubyValue;
import com.xruby.runtime.lang.annotation.RubyLevelMethod;
import com.xruby.runtime.lang.annotation.RubyLevelObject;

@RubyLevelObject(objectClass="Object")
public class RubyTopSelf {
	@RubyLevelMethod(name="include", singleton=true)
	public static RubyValue include(RubyValue receiver) {
        assert(RubyRuntime.TOP_LEVEL_SELF_VALUE == receiver);
        return RubyRuntime.ObjectClass;
    }
	
	@RubyLevelMethod(name="include", singleton=true)
	public static RubyValue include(RubyValue receiver, RubyValue arg) {
		assert(RubyRuntime.TOP_LEVEL_SELF_VALUE == receiver);
		
		RubyClass c = arg.getRubyClass().getRealClass();
		if (c != RubyRuntime.ModuleClass) {
			throw new RubyException(RubyRuntime.TypeErrorClass, "wrong argument type " + c.getName() + " (expected Module)");
		}
		RubyRuntime.ObjectClass.includeModule((RubyModule)arg);

		return RubyRuntime.ObjectClass;
    }
	
	@RubyLevelMethod(name="include", singleton=true)
	public static RubyValue include(RubyValue receiver, RubyArray args) {
        assert(RubyRuntime.TOP_LEVEL_SELF_VALUE == receiver);

        for (RubyValue v : args) {
            RubyClass c = v.getRubyClass().getRealClass();
            if (c != RubyRuntime.ModuleClass) {
                throw new RubyException(RubyRuntime.TypeErrorClass, "wrong argument type " + c.getName() + " (expected Module)");
            }
            RubyRuntime.ObjectClass.includeModule((RubyModule) v);
        }

        return RubyRuntime.ObjectClass;
    }
}

@@ -1,132 +1,122 @@
-package com.xruby.runtime.builtin;%0A%0Aimport com.xruby.runtime.lang.RubyClass;%0Aimport com.xruby.runtime.lang.RubyException;%0Aimport
+/**%0A * Copyright 2005-2007 Xue Yong Zhi, Ye Zheng%0A * Distributed under the GNU General Public License 2.0%0A */%0A%0Apackage
  com
@@ -134,24 +134,17 @@
 ime.
-lang.RubyModule;
+builtin;%0A
 %0Aimp
@@ -407,17 +407,20 @@
 pSelf %7B%0A
-%09
+    
 @RubyLev
@@ -452,33 +452,36 @@
 singleton=true)%0A
-%09
+    
 public static Ru
@@ -618,35 +618,37 @@
 ectClass;%0A    %7D%0A
-%09%0A%09
+%0A    
 @RubyLevelMethod
@@ -672,33 +672,36 @@
 singleton=true)%0A
-%09
+    
 public static Ru
@@ -753,18 +753,24 @@
  arg) %7B%0A
-%09%09
+        
 assert(R
@@ -819,282 +819,62 @@
 r);%0A
-%09%09%0A%09%09RubyClass c = arg.getRubyClass().getRealClass();%0A%09%09if (c != RubyRuntime.ModuleClass) %7B%0A%09%09%09throw new RubyException(RubyRuntime.TypeErrorClass, %22wrong argument type %22 + c.getName() + %22 (expected Module)%22);%0A%09%09%7D%0A%09%09RubyRuntime.ObjectClass.includeModule((RubyModule)arg);%0A%0A%09%09
+        RubyRuntime.ObjectClass.include(arg);%0A        
 retu
@@ -911,11 +911,13 @@
   %7D%0A
-%09%0A%09
+%0A    
 @Rub
@@ -965,9 +965,12 @@
 ue)%0A
-%09
+    
 publ
@@ -1101,299 +1101,8 @@
 r);%0A
-%0A        for (RubyValue v : args) %7B%0A            RubyClass c = v.getRubyClass().getRealClass();%0A            if (c != RubyRuntime.ModuleClass) %7B%0A                throw new RubyException(RubyRuntime.TypeErrorClass, %22wrong argument type %22 + c.getName() + %22 (expected Module)%22);%0A            %7D%0A    
     
@@ -1140,42 +1140,15 @@
 lude
-Module((RubyModule) v);%0A        %7D%0A
+(args);
 %0A   

fix self.include