Package org.jruby
Class RubyObject
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,InstanceVariables,InternalVariables,IRubyObject,CoreObjectType
- Direct Known Subclasses:
AbstractRubyMethod,Addrinfo,ArrayJavaProxyCreator,ConditionVariable,DynamicLibrary,Enums,Ifaddr,JavaObject,JavaProxy,JavaProxyReflectionObject,JRubyExecutionContextLocal,JRubyObjectInputStream,MemoryObject,Monitor,Mutex,Option,Queue,RubyArgsFile,RubyArithmeticSequence,RubyArray,RubyBinding,RubyBoolean,RubyChain,RubyClassPathVariable,RubyContinuation,RubyConverter,RubyDate,RubyDigest.DigestBase,RubyDigest.DigestClass,RubyDir,RubyEncoding,RubyEnumerator,RubyEnumerator.FeedValue,RubyException,RubyFileStat,RubyGenerator,RubyGzipFile,RubyHash,RubyIO,RubyMatchData,RubyModule,RubyNameError.RubyNameErrorMessage,RubyNil,RubyNumeric,RubyObject.Data,RubyObjectSpace.WeakMap,RubyPathname,RubyProc,RubyProcess.RubyStatus,RubyRandom,RubyRange,RubyRegexp,RubyRipper,RubySet,RubyString,RubyStringScanner,RubyStruct,RubySymbol,RubySyslog,RubyThread,RubyThread.Location,RubyThreadGroup,RubyTime,RubyYielder,StringIO,StructLayout.ArrayProxy,StructLayout.Field,ThreadFiber,TracePoint,Type,VariadicInvoker,ZStream
RubyObject represents the implementation of the Object class in Ruby. As such,
it defines very few methods of its own, inheriting most from the included
Kernel module.
Methods that are implemented here, such as "initialize" should be implemented
with care; reification of Ruby classes into Java classes can produce
conflicting method names in rare cases. See JRUBY-5906 for an example.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectAllocatorAllocator that inspects all methods for instance variables and chooses a concrete class to construct based on that.static final ObjectAllocatorDefault allocator instance for all Ruby objects.static final ObjectAllocatorFields 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, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, UNTRUST_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStampFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionRubyObject(RubyClass metaClass) Path for objects that don't taint and don't enter objectspace.RubyObject(Ruby runtime, RubyClass metaClass) Standard path for object creation.protectedRubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace) Path for objects who want to decide whether they don't want to be in ObjectSpace even when it is on.protectedRubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidWill make sure that this object is added to the current object space.final voidCall the Ruby initialize method with the supplied arguments and block.final voidcallInit(IRubyObject[] args, Block block) Call the Ruby initialize method with the supplied arguments and block.final voidcallInit(IRubyObject arg0, Block block) Call the Ruby initialize method with the supplied arguments and block.final voidcallInit(IRubyObject arg0, IRubyObject arg1, Block block) Call the Ruby initialize method with the supplied arguments and block.final voidcallInit(IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) Call the Ruby initialize method with the supplied arguments and block.final voidcallInit(ThreadContext context, Block block) final voidcallInit(ThreadContext context, IRubyObject[] args, Block block) final voidcallInit(ThreadContext context, IRubyObject arg0, Block block) final voidcallInit(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) final voidcallInit(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) final IRubyObjectconvertToType(RubyClass target, int convertMethodIndex) Deprecated.static RubyClasscreateObjectClass(Ruby runtime, RubyClass objectClass) Will create the Ruby class Object in the runtime specified.static IRubyObjectdig(ThreadContext context, IRubyObject obj, IRubyObject[] args, int idx) static IRubyObjectdig1(ThreadContext context, IRubyObject obj, IRubyObject arg1) static IRubyObjectdig2(ThreadContext context, IRubyObject obj, IRubyObject arg1, IRubyObject arg2) protected static booleaneqlInternal(ThreadContext context, IRubyObject a, IRubyObject b) Helper method for checking equality, first using Java identity equality, and then calling the "eql?" method.static booleanequalInternal(ThreadContext context, IRubyObject a, IRubyObject b) Helper method for checking equality, first using Java identity equality, and then calling the "==" method.booleanThis override does not do a "checked" dispatch.private static booleanfastNumEqualInternal(ThreadContext context, IRubyObject a, IRubyObject b) This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.inthashCode()This override does not do "checked" dispatch since Object usually has #hash defined.static RubyStringinspect(ThreadContext context, IRubyObject object) rb_inspect The internal helper that ensures a RubyString instance is returned so dangerous casting can be omitted Preferred over callMethod(context, "inspect")private static booleanisArrayDig(IRubyObject obj, JavaSites.ObjectSites sites) private static booleanisHashDig(IRubyObject obj, JavaSites.ObjectSites sites) private static booleanisStructDig(IRubyObject obj, JavaSites.ObjectSites sites) op_eqq(ThreadContext context, IRubyObject other) rb_equal The Ruby "===" method is used by default in case/when statements.static voidDeprecated.no longer used - uses Java's System.outprivate voidTries to support Java unserialization of Ruby objects.private static IRubyObjectreifyAndAllocate(Ruby runtime, RubyClass klass) Reify the class and allocate an instance.private static JavaSites.ObjectSitessites(ThreadContext context) specificEval(ThreadContext context, RubyModule mod, IRubyObject[] args, Block block, EvalType evalType) Deprecated.toRubyString(ThreadContext context) The default toString method is just a wrapper that calls the Ruby "to_s" method.toString()The default toString method is just a wrapper that calls the Ruby "to_s" method.private voidTries to support Java serialization of Ruby objects.Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, checkStringType19, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, defaultToJava, display, dup, ensureInstanceVariablesSettable, eql, eql_p, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, infectBy, infectBy, initialize, initialize_copy, initialize19, 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, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method, method_missing, method_missing19, method19, methods, methods, methods19, methodsImpl, nil_p, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_equal, op_equal_19, op_match, op_match19, op_not, op_not_equal, op_not_match, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, rbClone, rbInspect, recacheBuiltinMethods, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method_added, singleton_method_added19, singleton_method_removed, singleton_method_removed19, singleton_method_undefined, singleton_method_undefined19, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted, tainted_p, testFrozen, testFrozen, to_a, to_a, to_s, toJava, trust, type, type_deprecated, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
-
Field Details
-
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:
-
IVAR_INSPECTING_OBJECT_ALLOCATOR
Allocator that inspects all methods for instance variables and chooses a concrete class to construct based on that. This allows using specialized subclasses to hold instance variables in fields rather than always holding them in an array. -
REIFYING_OBJECT_ALLOCATOR
-
-
Constructor Details
-
RubyObject
Standard path for object creation. Objects are entered into ObjectSpace only if ObjectSpace is enabled. -
RubyObject
Path for objects that don't taint and don't enter objectspace. -
RubyObject
@Deprecated protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted) Deprecated. -
RubyObject
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)
-
-
Method Details
-
reifyAndAllocate
Reify the class and allocate an instance.- Parameters:
runtime- the current runtimeklass- the target Ruby class- Returns:
- a new instance of the now-reified class
-
createObjectClass
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. -
attachToObjectSpace
public void attachToObjectSpace()Will make sure that this object is added to the current object space.- See Also:
-
getNativeClassIndex
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:
getNativeClassIndexin interfaceCoreObjectType- Overrides:
getNativeClassIndexin classRubyBasicObject- See Also:
-
puts
Deprecated.no longer used - uses Java's System.outSimple helper to print any objects. -
equals
This override does not do a "checked" dispatch.- Overrides:
equalsin classRubyBasicObject- See Also:
-
toRubyString
The default toString method is just a wrapper that calls the Ruby "to_s" method. This will raise if it is not actually a Ruby String.- Parameters:
context- thread context this is executing on.- Returns:
- the string.
-
toString
The default toString method is just a wrapper that calls the Ruby "to_s" method. -
callInit
Call the Ruby initialize method with the supplied arguments and block. -
callInit
Call the Ruby initialize method with the supplied arguments and block. -
callInit
Call the Ruby initialize method with the supplied arguments and block. -
callInit
Call the Ruby initialize method with the supplied arguments and block. -
callInit
Call the Ruby initialize method with the supplied arguments and block. -
callInit
-
callInit
-
callInit
-
callInit
-
callInit
public final void callInit(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) -
convertToType
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, EvalType evalType) 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
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_eqqin interfaceIRubyObject- Overrides:
op_eqqin classRubyBasicObject
-
equalInternal
Helper method for checking equality, first using Java identity equality, and then calling the "==" method. -
fastNumEqualInternal
-
eqlInternal
Helper method for checking equality, first using Java identity equality, and then calling the "eql?" method. -
hashCode
public int hashCode()This override does not do "checked" dispatch since Object usually has #hash defined.- Overrides:
hashCodein classRubyBasicObject- See Also:
-
inspect
rb_inspect The internal helper that ensures a RubyString instance is returned so dangerous casting can be omitted Preferred over callMethod(context, "inspect") -
dig
-
dig1
-
dig2
public static IRubyObject dig2(ThreadContext context, IRubyObject obj, IRubyObject arg1, IRubyObject arg2) -
isStructDig
-
isHashDig
-
isArrayDig
-
writeObject
Tries to support Java serialization of Ruby objects. This is still experimental and might not work.- Throws:
IOException
-
readObject
Tries to support Java unserialization of Ruby objects. This is still experimental and might not work.- Throws:
IOExceptionClassNotFoundException
-
sites
-