1 29 package org.jruby.runtime.builtin.meta; 30 31 import org.jruby.Ruby; 32 import org.jruby.RubyClass; 33 import org.jruby.RubyModule; 34 import org.jruby.RubyObject; 35 import org.jruby.runtime.Arity; 36 import org.jruby.runtime.ClassIndex; 37 import org.jruby.runtime.ObjectAllocator; 38 import org.jruby.runtime.builtin.IRubyObject; 39 import org.jruby.util.collections.SinglyLinkedList; 40 41 46 public class ObjectMetaClass extends AbstractMetaClass { 47 public ObjectMetaClass(Ruby runtime) { 49 super(runtime, null , null, OBJECT_ALLOCATOR, null, "Object"); 50 51 this.builtinClass = RubyObject.class; 52 this.index = ClassIndex.OBJECT; 53 } 54 55 protected ObjectMetaClass(Ruby runtime, RubyClass metaClass, RubyClass superClass, ObjectAllocator allocator, 57 SinglyLinkedList parentCRef, String name, Class builtinClass) { 58 super(runtime, metaClass, superClass, allocator, parentCRef, name); 59 60 this.builtinClass = builtinClass; 61 } 62 63 protected ObjectMetaClass(String name, Class builtinClass, RubyClass superClass, ObjectAllocator allocator) { 64 this(name, builtinClass, superClass, allocator, superClass.getRuntime().getClass("Object").getCRef()); 65 } 66 67 protected ObjectMetaClass(String name, Class builtinClass, RubyClass superClass, ObjectAllocator allocator, SinglyLinkedList parentCRef) { 68 super(superClass.getRuntime(), superClass.getRuntime().getClass("Class"), superClass, allocator, parentCRef, name); 69 70 assert builtinClass != null; 71 assert superClass != null; 73 74 this.builtinClass = builtinClass; 75 76 makeMetaClass(superClass.getMetaClass(), getCRef()); 77 inheritedBy(superClass); 78 79 if(name != null) { 80 ((RubyModule)parentCRef.getValue()).setConstant(name, this); 81 } 82 } 83 84 protected class ObjectMeta extends Meta { 85 protected void initializeClass() { 86 definePrivateMethod("initialize", Arity.optional()); 87 definePrivateMethod("inherited", Arity.singleArgument()); 88 defineFastMethod("initialize_copy", Arity.singleArgument()); 89 } 90 }; 91 92 protected Meta getMeta() { 93 return new ObjectMeta(); 94 } 95 96 public static ObjectAllocator OBJECT_ALLOCATOR = new ObjectAllocator() { 97 public IRubyObject allocate(Ruby runtime, RubyClass klass) { 98 IRubyObject instance = new RubyObject(runtime, klass); 99 instance.setMetaClass(klass); 100 101 return instance; 102 } 103 }; 104 105 public void initializeClass() { 106 getMeta().initializeClass(); 107 } 108 109 } 110 | Popular Tags |