1 30 package org.jruby.runtime.builtin.meta; 31 32 import org.jruby.Ruby; 33 import org.jruby.RubyClass; 34 import org.jruby.RubySymbol; 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 public class SymbolMetaClass extends ObjectMetaClass { 42 public SymbolMetaClass(Ruby runtime) { 43 super("Symbol", RubySymbol.class, runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR); 44 this.index = ClassIndex.SYMBOL; 45 } 46 47 private SymbolMetaClass(String name, RubyClass superClass, ObjectAllocator allocator, SinglyLinkedList parentCRef) { 48 super(name, RubySymbol.class, superClass, allocator, parentCRef); 49 } 50 51 protected class SymbolMeta extends Meta { 52 public void initializeClass() { 53 defineFastMethod("==", Arity.singleArgument(), "equal"); 54 55 defineFastMethod("freeze", Arity.noArguments()); 56 defineFastMethod("hash", Arity.noArguments()); 57 defineFastMethod("inspect", Arity.noArguments()); 58 defineFastMethod("taint", Arity.noArguments()); 59 defineFastMethod("to_i", Arity.noArguments()); 60 defineFastMethod("to_s", Arity.noArguments()); 61 defineFastMethod("to_sym", Arity.noArguments()); 62 defineFastSingletonMethod("all_symbols", Arity.noArguments()); 63 defineAlias("id2name", "to_s"); 64 defineAlias("to_int", "to_i"); 65 66 getMetaClass().undefineMethod("new"); 67 } 68 }; 69 70 protected Meta getMeta() { 71 return new SymbolMeta(); 72 } 73 74 public RubyClass newSubClass(String name, SinglyLinkedList parentCRef) { 75 return new SymbolMetaClass(name, this, ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR, parentCRef); 76 } 77 78 public IRubyObject all_symbols() { 79 return getRuntime().newArrayNoCopy(getRuntime().getSymbolTable().all_symbols()); 80 } 81 } 82 | Popular Tags |