org.jruby
Class RubyObject

java.lang.Object
  extended by org.jruby.RubyBasicObject
      extended by org.jruby.RubyObject
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<IRubyObject>, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType
Direct Known Subclasses:
AbstractMemory, ArrayJavaProxyCreator, DynamicLibrary, Enum, FiberLibrary.Fiber, JavaAccessibleObject, JavaObject, JavaProxy, JavaProxyReflectionObject, JRubyObjectInputStream, MethodMissing, PsychEmitter, PsychParser, RubyArray, RubyBinding, RubyBoolean, RubyClassPathVariable, RubyContinuation, RubyConverter, RubyData, RubyDigest.DigestBase, RubyDigest.DigestClass, RubyDir, RubyEncoding, RubyEnumerator, RubyException, RubyFileStat, RubyHash, RubyIconv, RubyIO, RubyJRuby.JRubyExecutionContextLocal, RubyMatchData, RubyMethod, RubyModule, RubyNameError.RubyNameErrorMessage, RubyNil, RubyNumeric, RubyObject.Data, RubyProc, RubyProcess.RubyStatus, RubyRandom, RubyRange, RubyRegexp, RubyString, RubyStringIO, RubyStringScanner, RubyStruct, RubySymbol, RubyThread, RubyThreadGroup, RubyTime, RubyTuple, RubyYielder, RubyZlib.RubyGzipFile, RubyZlib.ZStream, Struct, StructByReference, StructLayout.ArrayProxy, StructLayout.Field, ThreadLibrary.ConditionVariable, ThreadLibrary.Mutex, ThreadLibrary.Queue, Type, VariadicInvoker, WeakRef

public class RubyObject
extends RubyBasicObject

RubyObject is the only implementation of the IRubyObject. Every Ruby object in JRuby is represented by something that is an instance of RubyObject. In some of the core class implementations, this means doing a subclass that extends RubyObject, in other cases it means using a simple RubyObject instance and the data field to store specific information about the Ruby object. Some care has been taken to make the implementation be as monomorphic as possible, so that the Java Hotspot engine can improve performance of it. That is the reason for several patterns that might seem odd in this class. The IRubyObject interface used to have lots of methods for different things, but these have now mostly been refactored into several interfaces that gives access to that specific part of the object. This gives us the possibility to switch out that subsystem without changing interfaces again. For example, instance variable and internal variables are handled this way, but the implementation in RubyObject only returns "this" in RubyBasicObject.getInstanceVariables() and RubyBasicObject.getInternalVariables().

Author:
jpetersen
See Also:
Serialized Form

Nested Class Summary
static class RubyObject.Data
           
 
Nested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer
 
Field Summary
static ObjectAllocator OBJECT_ALLOCATOR
          Default allocator instance for all Ruby objects.
static ObjectAllocator REIFYING_OBJECT_ALLOCATOR
           
 
Fields inherited from class org.jruby.RubyBasicObject
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, TAINTED_F, UNDEF, UNTRUSTED_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
  RubyObject(RubyClass metaClass)
          Path for objects that don't taint and don't enter objectspace.
  RubyObject(Ruby runtime, RubyClass metaClass)
          Standard path for object creation.
protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace)
           
protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted)
          Path for objects who want to decide whether they don't want to be in ObjectSpace even when it is on.
 
Method Summary
 void attachToObjectSpace()
          Will make sure that this object is added to the current object space.
 void callInit(Block block)
          Call the Ruby initialize method with the supplied arguments and block.
 void callInit(IRubyObject[] args, Block block)
          Call the Ruby initialize method with the supplied arguments and block.
 void callInit(IRubyObject arg0, Block block)
          Call the Ruby initialize method with the supplied arguments and block.
 void callInit(IRubyObject arg0, IRubyObject arg1, Block block)
          Call the Ruby initialize method with the supplied arguments and block.
 void callInit(IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
          Call the Ruby initialize method with the supplied arguments and block.
 IRubyObject convertToType(RubyClass target, int convertMethodIndex)
          Deprecated. 
static RubyClass createObjectClass(Ruby runtime, RubyClass objectClass)
          Will create the Ruby class Object in the runtime specified.
protected static boolean eqlInternal(ThreadContext context, IRubyObject a, IRubyObject b)
          Helper method for checking equality, first using Java identity equality, and then calling the "eql?" method.
protected static boolean equalInternal(ThreadContext context, IRubyObject a, IRubyObject b)
          Helper method for checking equality, first using Java identity equality, and then calling the "==" method.
 boolean equals(java.lang.Object other)
          This method is just a wrapper around the Ruby "==" method, provided so that RubyObjects can be used as keys in the Java HashMap object underlying RubyHash.
 int getNativeTypeIndex()
          This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.
 int hashCode()
          Override the Object#hashCode method to make sure that the Ruby hash is actually used as the hashcode for Ruby objects.
 IRubyObject initialize()
           
 IRubyObject op_eqq(ThreadContext context, IRubyObject other)
          rb_equal The Ruby "===" method is used by default in case/when statements.
static void puts(java.lang.Object obj)
          Simple helper to print any objects.
 IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject[] args, Block block)
          Deprecated. 
 java.lang.String toString()
          The default toString method is just a wrapper that calls the Ruby "to_s" method.
 
Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkFrozen, checkStringType, checkStringType19, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, display, dup, ensureInstanceVariablesSettable, eql_p, eql, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInternalVariable, hasVariables, id_deprecated, id, infectBy, initialize_copy, initialize19, initialize19, initialize19, initialize19, initialize19, initObjectId, inspect, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval19, instance_eval19, instance_eval19, instance_eval19, instance_exec, instance_exec19, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, instance_variables19, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method_missing19, method, method19, methods, methods, methods19, nil_p, op_cmp, op_equal_19, op_equal, op_match, op_match19, op_not_equal, op_not_match, op_not, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, send19, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, setUntrusted, setVariable, singleton_method_added19, singleton_method_removed19, singleton_method_undefined19, singleton_methods, singleton_methods19, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted_p, testFrozen, testFrozen, to_a, to_s, toJava, trust, type_deprecated, type, untaint, untrust, untrusted_p, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OBJECT_ALLOCATOR

public static final ObjectAllocator OBJECT_ALLOCATOR
Default allocator instance for all Ruby objects. The only reason to not use this allocator is if you actually need to have all instances of something be a subclass of RubyObject.

See Also:
ObjectAllocator

REIFYING_OBJECT_ALLOCATOR

public static final ObjectAllocator REIFYING_OBJECT_ALLOCATOR
Constructor Detail

RubyObject

public RubyObject(Ruby runtime,
                  RubyClass metaClass)
Standard path for object creation. Objects are entered into ObjectSpace only if ObjectSpace is enabled.


RubyObject

public RubyObject(RubyClass metaClass)
Path for objects that don't taint and don't enter objectspace.


RubyObject

protected RubyObject(Ruby runtime,
                     RubyClass metaClass,
                     boolean useObjectSpace,
                     boolean canBeTainted)
Path for objects who want to decide whether they don't want to be in ObjectSpace even when it is on. (notably used by objects being considered immediate, they'll always pass false here)


RubyObject

protected RubyObject(Ruby runtime,
                     RubyClass metaClass,
                     boolean useObjectSpace)
Method Detail

createObjectClass

public static RubyClass createObjectClass(Ruby runtime,
                                          RubyClass objectClass)
Will create the Ruby class Object in the runtime specified. This method needs to take the actual class as an argument because of the Object class' central part in runtime initialization.


initialize

public IRubyObject initialize()
Overrides:
initialize in class RubyBasicObject

attachToObjectSpace

public void attachToObjectSpace()
Will make sure that this object is added to the current object space.

See Also:
ObjectSpace

getNativeTypeIndex

public int getNativeTypeIndex()
This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are. Will generally return a value from org.jruby.runtime.ClassIndex

Specified by:
getNativeTypeIndex in interface CoreObjectType
Overrides:
getNativeTypeIndex in class RubyBasicObject
Returns:
the ClassIndex of the native type this object was constructed from
See Also:
org.jruby.runtime.ClassInde

puts

public static void puts(java.lang.Object obj)
Simple helper to print any objects.


equals

public boolean equals(java.lang.Object other)
This method is just a wrapper around the Ruby "==" method, provided so that RubyObjects can be used as keys in the Java HashMap object underlying RubyHash.

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
The default toString method is just a wrapper that calls the Ruby "to_s" method.

Overrides:
toString in class java.lang.Object

callInit

public final void callInit(IRubyObject[] args,
                           Block block)
Call the Ruby initialize method with the supplied arguments and block.


callInit

public final void callInit(Block block)
Call the Ruby initialize method with the supplied arguments and block.


callInit

public final void callInit(IRubyObject arg0,
                           Block block)
Call the Ruby initialize method with the supplied arguments and block.


callInit

public final void callInit(IRubyObject arg0,
                           IRubyObject arg1,
                           Block block)
Call the Ruby initialize method with the supplied arguments and block.


callInit

public final void callInit(IRubyObject arg0,
                           IRubyObject arg1,
                           IRubyObject arg2,
                           Block block)
Call the Ruby initialize method with the supplied arguments and block.


convertToType

@Deprecated
public final IRubyObject convertToType(RubyClass target,
                                                  int convertMethodIndex)
Deprecated. 

Tries to convert this object to the specified Ruby type, using a specific conversion method.


specificEval

@Deprecated
public IRubyObject specificEval(ThreadContext context,
                                           RubyModule mod,
                                           IRubyObject[] args,
                                           Block block)
Deprecated. 

specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments. If a block is given, this will be yielded in the specific context of this object. If no block is given then a String-like object needs to be the first argument, and this string will be evaluated. Second and third arguments in the args-array is optional, but can contain the filename and line of the string under evaluation.


op_eqq

public IRubyObject op_eqq(ThreadContext context,
                          IRubyObject other)
rb_equal The Ruby "===" method is used by default in case/when statements. The Object implementation first checks Java identity equality and then calls the "==" method too.

Specified by:
op_eqq in interface IRubyObject
Overrides:
op_eqq in class RubyBasicObject

equalInternal

protected static boolean equalInternal(ThreadContext context,
                                       IRubyObject a,
                                       IRubyObject b)
Helper method for checking equality, first using Java identity equality, and then calling the "==" method.


eqlInternal

protected static boolean eqlInternal(ThreadContext context,
                                     IRubyObject a,
                                     IRubyObject b)
Helper method for checking equality, first using Java identity equality, and then calling the "eql?" method.


hashCode

public int hashCode()
Override the Object#hashCode method to make sure that the Ruby hash is actually used as the hashcode for Ruby objects. If the Ruby "hash" method doesn't return a number, the Object#hashCode implementation will be used instead.

Overrides:
hashCode in class java.lang.Object


Copyright © 2002-2009 JRuby Team. All Rights Reserved.