Package org.jruby
Class RubyBasicObject
java.lang.Object
org.jruby.RubyBasicObject
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,InstanceVariables,InternalVariables,IRubyObject,CoreObjectType
- Direct Known Subclasses:
RubyObject
public class RubyBasicObject
extends Object
implements Cloneable, IRubyObject, Serializable, Comparable<IRubyObject>, CoreObjectType, InstanceVariables, InternalVariables
RubyBasicObject is the only implementation of the
IRubyObject. Every Ruby object in JRuby
is represented by something that is an instance of RubyBasicObject. In
the core class implementations, this means doing a subclass
that extends RubyBasicObject. In other cases it means using a simple
RubyBasicObject instance and its data fields 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 getInstanceVariables() and
getInternalVariables().
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 ClassesModifier and TypeClassDescriptionstatic classClass that keeps track of the finalizers for the object under operation. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final ObjectAllocatorDefault allocator instance for all Ruby objects.static final intDeprecated.static final StringThe error message used when some one tries to modify an instance variable in a high security setting.static final intstatic final intDeprecated.protected intobject flagsstatic final intstatic final intDeprecated.protected RubyClassThe class of this objectstatic final IRubyObjectA value that is used as a null sentinel in among other places the RubyArray implementation.static final intThis flag is a bit funny.static final intDeprecated.static final longoffset of the varTableTamp field in RubyBasicObjectstatic final intstatic final IRubyObjectA value that specifies an undefined value.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final longoffset of the varTable field in RubyBasicObjectObject[]variable table, lazily allocated as needed (if needed)intlocking stamp for Unsafe ops updating the vartableFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateIt's not valid to create a totally empty RubyObject.RubyBasicObject(RubyClass metaClass) Path for objects that don't taint and don't enter objectspace.RubyBasicObject(Ruby runtime, RubyClass metaClass) Standard path for object creation.protectedRubyBasicObject(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.protectedRubyBasicObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified object as a finalizer for this object.Internal method that helps to convert any object into the format of a class name and a hex string inside of #<>.rb_to_id Will try to convert this object to a String using the Ruby "to_str" if the object isn't already a String.asString()rb_obj_as_string First converts this object into a String using the "to_s" method, infects it with the current taint and returns it.final IRubyObjectcallMethod(String name) final IRubyObjectcallMethod(String name, IRubyObject arg) final IRubyObjectcallMethod(String name, IRubyObject... args) final IRubyObjectcallMethod(ThreadContext context, int methodIndex, String name) Deprecated.final IRubyObjectcallMethod(ThreadContext context, int methodIndex, String name, IRubyObject arg) Deprecated.final IRubyObjectcallMethod(ThreadContext context, String name) Will invoke a named method with no arguments and no block.final IRubyObjectcallMethod(ThreadContext context, String name, IRubyObject arg) Will invoke a named method with one argument and no block with functional invocation.final IRubyObjectcallMethod(ThreadContext context, String name, IRubyObject[] args) Will invoke a named method with the supplied arguments and no block with functional invocation.final IRubyObjectcallMethod(ThreadContext context, String name, IRubyObject[] args, Block block) Will invoke a named method with the supplied arguments and supplied block with functional invocation.callSuper(ThreadContext context, IRubyObject[] args, Block block) Deprecated.rb_check_array_type Returns the result of trying to convert this object to an Array with "to_ary".final IRubyObjectcheckCallMethod(ThreadContext context, String name) Will invoke a named method with no arguments and no block if that method or a custom method missing exists.final IRubyObjectcheckCallMethod(ThreadContext context, JavaSites.CheckedSites sites) Will invoke a named method with no arguments and no block if that method or a custom method missing exists.voidThe actual method that checks frozen with the default frozen message from MRI.rb_check_string_type Tries to return a coerced string representation of this object, using "to_str".final IRubyObjectDeprecated.intcompareTo(IRubyObject other) Compares this Ruby object with another.Tries to convert this object to a Ruby Array using the "to_ary" method.Tries to convert this object to a Ruby Float using the "to_f" method.Tries to convert this object to a Ruby Hash using the "to_hash" method.Tries to convert this object to a Ruby Integer using the "to_int" method.convertToInteger(int methodIndex, String convertMethod) Deprecated.convertToInteger(String convertMethod) Tries to convert this object to a Ruby Integer using the supplied conversion method.Tries to convert this object to a Ruby String using the "to_str" method.voidCopies all instance variables from the given object into the receivervoidLots of MRI objects keep their state in non-lookupable ivars (e:g.static RubyClasscreateBasicObjectClass(Ruby runtime, RubyClass objectClass) Will create the Ruby class Object in the runtime specified.Our version of Data_Get_Struct.Deprecated.voiddataWrapStruct(Object obj) Our version of Data_Wrap_Struct.raw (id) strings are not properly encoded but in an iso_8859_1 form.(package private) final <T> TdefaultToJava(Class<T> target) display(ThreadContext context, IRubyObject[] args) rb_obj_display call-seq: obj.display(port=$>) => nil Prints obj on the given port (default$>).dup()RubyMethod dup.final voidMakes sure that instance variables can be set on this object, including information about whether this object is frozen, or tainted.booleaneql(IRubyObject other) method used for Hash key comparison (specialized for String, Symbol and Fixnum) Will by default just call the Ruby method "eql?"eql_p(IRubyObject obj) rb_obj_equal Just like "==" and "equal?", "eql?" will use identity equality for Object.equal_p(ThreadContext context, IRubyObject other) rb_obj_equal Will use Java identity equality.equal_p19(ThreadContext context, IRubyObject other) Deprecated.protected static booleanequalInternal(ThreadContext context, IRubyObject that, IRubyObject other) Helper method for checking equality, first using Java identity equality, and then calling the "==" method.booleanThis 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.evalUnder(ThreadContext context, RubyModule under, RubyString src, String file, int line, EvalType evalType) Evaluates the string src with self set to the current object, using the module under as the context.extend(IRubyObject[] args) rb_obj_extend call-seq: obj.extend(module, ...) => obj Adds to _obj_ the instance methods from each module given as a parameter.fastGetInstanceVariable(String internedName) Deprecated.fastGetInternalVariable(String internedName) Deprecated.booleanfastHasInstanceVariable(String internedName) Deprecated.booleanfastHasInternalVariable(String internedName) Deprecated.fastSetInstanceVariable(String internedName, IRubyObject value) Deprecated.voidfastSetInternalVariable(String internedName, Object value) Deprecated.freeze(ThreadContext context) rb_obj_freeze call-seq: obj.freeze => obj Prevents further modifications to obj.frozen_p(ThreadContext context) rb_obj_frozen_p call-seq: obj.frozen? => true or false Returns the freeze status of obj.final Objectfinal booleangetFlag(int flag) Get the value of a custom flag on this object.protected RubyModulegetInstanceVariable(String name) Returns the named instance variable if present, else null.Gets a list of all variables in this object.Gets a name list of all variables in this object.Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.getInternalVariable(String name) Returns the named internal variable if present, else null.Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.Will return the Java interface that most closely can represent this object, when working through Java integration translations.final RubyClassif exist return the meta-class else return the type of the object.static RubyClassgetMetaClass(IRubyObject arg) Return the ClassIndex for the native type this object was constructed from.final ObjectDeprecated.final intDeprecated.protected longThe logic here is to use the special objectId accessor slot from the parent as a lazy store for an object symbol.final RubyWill return the runtime that this object is associated with.rb_singleton_class Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean Will either return the existing singleton class for this object, or create a new one and return that.protected RubyClassprotected RubyClassrb_singleton_class_clone Will make sure that if the current objects class is a singleton, it will get cloned.final RubyClassgetType()RubyMethod getType.getVariable(int index) intDeprecated.Gets a list of all variables in this object.Gets a name list of all variables in this object.hash()rb_obj_id Will return the hash code of this object.inthashCode()Override the Object#hashCode method to make sure that the Ruby hash is actually used as the hashcode for Ruby objects.final IRubyObjectbooleanhasInstanceVariable(String name) Returns true if object has the named instance variable.protected booleanCheck whether this object has any *set* instance variables unrelated to object_id, FFI, and ObjectSpace (which also use hidden ivar slots).booleanhasInternalVariable(String name) Returns true if object has the named internal variable.booleanReturns true if object has any variablesid()rb_obj_id Return the internal id of an object.(package private) final RubyBasicObjectinfectBy(int tuFlags) (package private) final RubyBasicObjectinfectBy(RubyBasicObject obj) infectBy(IRubyObject obj) OBJ_INFECT Infects this object with traits from the argument obj.private static IRubyObjectinitCopy(ThreadContext context, IRubyObject clone, IRubyObject original, boolean doClone) init_copy Initializes a copy with variable and special instance variable information, and then call the initialize_copy Ruby method.initialize(ThreadContext context) initialize_copy(IRubyObject original) rb_obj_init_copy Initializes this object as a copy of the original, that is the parameter to this object.initialize19(ThreadContext context) Deprecated.inspect()rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj.(package private) 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")protected intFor most objects, the hash used in the default #inspect is just the identity hashcode of the actual object.private RubyStringinspectObj(Ruby runtime, RubyString part) inspect_obj The internal helper method that takes care of the part of the inspection that inspects instance variables.instance_eval(ThreadContext context, Block block) rb_obj_instance_eval call-seq: obj.instance_eval(string [, filename [, lineno]] ) => obj obj.instance_eval {| | block } => obj Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (_obj_).instance_eval(ThreadContext context, IRubyObject arg0, Block block) instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) instance_eval19(ThreadContext context, Block block) Deprecated.instance_eval19(ThreadContext context, IRubyObject arg0, Block block) Deprecated.instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) Deprecated.instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) Deprecated.instance_exec(ThreadContext context, IRubyObject[] args, Block block) rb_obj_instance_exec call-seq: obj.instance_exec(arg...) {|var...| block } => obj Executes the given block within the context of the receiver (_obj_).instance_exec19(ThreadContext context, IRubyObject[] args, Block block) Deprecated.instance_of_p(ThreadContext context, IRubyObject type) rb_obj_is_instance_of call-seq: obj.instance_of?(class) => true or false Returnstrueif obj is an instance of the given class.instance_variable_defined_p(ThreadContext context, IRubyObject name) rb_obj_ivar_defined call-seq: obj.instance_variable_defined?(symbol) => true or false Returnstrueif the given instance variable is defined in obj.instance_variable_get(ThreadContext context, IRubyObject name) rb_obj_ivar_get call-seq: obj.instance_variable_get(symbol) => obj Returns the value of the given instance variable, or nil if the instance variable is not set.instance_variable_set(IRubyObject name, IRubyObject value) rb_obj_ivar_set call-seq: obj.instance_variable_set(symbol, obj) => obj Sets the instance variable names by symbol to object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation.instance_variables(ThreadContext context) rb_obj_instance_variables call-seq: obj.instance_variables => array Returns an array of instance variable names for the receiver.instance_variables19(ThreadContext context) Deprecated.booleanA method to determine whether the method named by methodName is a builtin method.booleanisClass()Specifically polymorphic method that are meant to be overridden by classes to specify that they are classes in an easy way.final booleanisFalse()Is this value a falsey value or not? Based on theFALSE_Fflag.booleanisFrozen()Is this value frozen or not? Shortcut for doing getFlag(FROZEN_F).booleanIs object immediate (def: Fixnum, Symbol, true, false, nil?).booleanisModule()Specifically polymorphic method that are meant to be overridden by modules to specify that they are modules in an easy way.final booleanisNil()Does this object represent nil? See the docs for theNIL_Fflag for more information.booleanbooleanbooleanisTaint()Gets the taint.final booleanisTrue()Is this value a truthy value or not? Based on theFALSE_Fflag.booleanDeprecated.kind_of_p(ThreadContext context, IRubyObject type) rb_obj_is_kind_of call-seq: obj.is_a?(class) => true or false obj.kind_of?(class) => true or false Returnstrueif class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.makeMetaClass(RubyClass superClass) rb_make_metaclass Will create a new meta class, insert this in the chain of classes for this specific object, and return the generated meta class.method(IRubyObject name) rb_obj_method call-seq: obj.method(sym) => method Looks up the named method as a receiver in obj, returning aMethodobject (or raisingNameError).static IRubyObjectmethod_missing(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) static IRubyObjectmethod_missing19(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Deprecated.method19(IRubyObject name) Deprecated.methods(ThreadContext context, IRubyObject... args) rb_obj_methods call-seq: obj.methods => array Returns a list of the names of methods publicly accessible in obj.final IRubyObjectmethods(ThreadContext context, IRubyObject[] args, boolean useSymbols) Deprecated.methods19(ThreadContext context, IRubyObject[] args) Deprecated.(package private) final IRubyObjectmethodsImpl(ThreadContext context, boolean all) nil_p(ThreadContext context) rb_false call_seq: nil.nil? => true.nil? => false Only the object nil responds truetonil?.protected static intnonFixnumHashCode(IRubyObject hashValue) protected static booleanOBJ_INIT_COPY(IRubyObject obj, IRubyObject orig) protected static voidobjInitCopy(IRubyObject obj, IRubyObject orig) op_cmp(ThreadContext context, IRubyObject other) op_eqq(ThreadContext context, IRubyObject other) op_equal(ThreadContext context, IRubyObject obj) rb_obj_equal Will by default use identity equality to compare objects.op_equal_19(ThreadContext context, IRubyObject obj) Deprecated.op_match(ThreadContext context, IRubyObject arg) rb_obj_pattern_match call-seq: obj =~ other => nil Pattern Match---Overridden by descendents (notablyRegexpandString) to provide meaningful pattern-match semantics.op_match19(ThreadContext context, IRubyObject arg) Deprecated.op_not(ThreadContext context) op_not_equal(ThreadContext context, IRubyObject other) The != method implemented for BasicObject.op_not_match(ThreadContext context, IRubyObject arg) Invert the match operator.private_methods(ThreadContext context, IRubyObject[] args) rb_obj_private_methods call-seq: obj.private_methods(all=true) => array Returns the list of private methods accessible to obj.private_methods19(ThreadContext context, IRubyObject[] args) Deprecated.protected_methods(ThreadContext context, IRubyObject[] args) rb_obj_protected_methods call-seq: obj.protected_methods(all=true) => array Returns the list of protected methods accessible to obj.protected_methods19(ThreadContext context, IRubyObject[] args) Deprecated.public_methods(ThreadContext context, IRubyObject[] args) rb_obj_public_methods call-seq: obj.public_methods(all=true) => array Returns the list of public methods accessible to obj.public_methods19(ThreadContext context, IRubyObject[] args) Deprecated.private voidrbClone()RubyMethod clone.rbClone(ThreadContext context, IRubyObject maybeOpts) private RubyBasicObjectrbCloneInternal(ThreadContext context, boolean freeze) static IRubyObjectrbInspect(ThreadContext context, IRubyObject obj) private voidDeserialization proceeds as follows: Deserialize the object instance.(package private) static voidrecacheBuiltinMethods(Ruby runtime) remove_instance_variable(ThreadContext context, IRubyObject name, Block block) rb_obj_remove_instance_variable call-seq: obj.remove_instance_variable(symbol) => obj Removes the named instance variable from obj, returning that variable's value.voidRemove all the finalizers for this object.removeInstanceVariable(String name) Removes the named instance variable, if present, returning its value.removeInternalVariable(String name) Removes the named internal variable, if present, returning its value.final RubyBooleanrespond_to_p(IRubyObject mname) Deprecated.final RubyBooleanrespond_to_p(IRubyObject mname, IRubyObject includePrivate) Deprecated.(package private) final RubyBooleanrespond_to_p(ThreadContext context, IRubyObject methodName, boolean includePrivate) final RubyBooleanrespond_to_p19(IRubyObject mname) Deprecated.final RubyBooleanrespond_to_p19(IRubyObject mname, IRubyObject includePrivate) Deprecated.final booleanrespondsTo(String name) Does this object respond to the specified message? Uses a shortcut if it can be proved that respond_to? and respond_to_missing? haven't been overridden.final booleanrespondsToMissing(String name) Does this object respond to the specified message via "method_missing?"final booleanrespondsToMissing(String name, boolean incPrivate) Does this object respond to the specified message via "method_missing?"send(ThreadContext context, Block block) Deprecated.send(ThreadContext context, IRubyObject[] args, Block block) send(ThreadContext context, IRubyObject arg0, Block block) send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) send19(ThreadContext context, IRubyObject[] args, Block block) Deprecated.send19(ThreadContext context, IRubyObject arg0, Block block) Deprecated.send19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) Deprecated.send19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) Deprecated.final voidsetFFIHandle(Object value) final voidsetFlag(int flag, boolean set) Sets or unsets a flag on this object.voidsetFrozen(boolean frozen) Sets whether this object is frozen or not.setInstanceVariable(String name, IRubyObject value) rb_iv_set / rb_ivar_setvoidsetInternalVariable(String name, Object value) Sets the named internal variable to the specified value.voidsetMetaClass(RubyClass metaClass) Makes it possible to change the metaclass of an object.final voidsetNativeHandle(Object value) Deprecated.voidsetTaint(boolean taint) Sets the taint flag.voidsetUntrusted(boolean untrusted) Deprecated.private BlocksetupBlock(Block block, EvalType evalType) voidsetVariable(int index, Object value) singleton_method(IRubyObject name) static IRubyObjectsingleton_method_added(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) static IRubyObjectsingleton_method_added19(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) Deprecated.static IRubyObjectsingleton_method_removed(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) static IRubyObjectsingleton_method_removed19(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) Deprecated.static IRubyObjectsingleton_method_undefined(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) static IRubyObjectsingleton_method_undefined19(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) Deprecated.singleton_methods(ThreadContext context, IRubyObject[] args) rb_obj_singleton_methods call-seq: obj.singleton_methods(all=true) => array Returns an array of the names of singleton methods for obj.private static JavaSites.BasicObjectSitessites(ThreadContext context) Retrieve the call sites for this class.specificEval(ThreadContext context, RubyModule mod, Block block, EvalType evalType) specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.specificEval(ThreadContext context, RubyModule mod, IRubyObject arg, Block block, EvalType evalType) specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, Block block, EvalType evalType) specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block, EvalType evalType) specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.voidsyncVariables(List<Variable<Object>> variables) Deprecated.voidsyncVariables(IRubyObject other) Sync one this object's variables with other's - this is used to make rbClone work correctly.protected final voidDeprecated.taint(ThreadContext context) rb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the$SAFElevel is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.(package private) IRubyObjecttainted()Set the object tainted and return it.tainted_p(ThreadContext context) rb_obj_tainted call-seq: obj.tainted? => true or false Returnstrueif the object is tainted.protected final voidrb_frozen_class_p Helper to test whether this object is frozen, and if it is will throw an exception based on the message.protected final voidtestFrozen(String message) rb_frozen_class_p Helper to test whether this object is frozen, and if it is will throw an exception based on the message.to_a()Deprecated.to_a(ThreadContext context) rb_any_to_a call-seq: obj.to_a -> anArray Returns an array representation of obj.to_s()rb_any_to_s call-seq: obj.to_s => string Returns a string representing obj.<T> TConvert the object to the specified Java class, if possible.trust(ThreadContext context) Deprecated.type()rb_obj_class Returns the real class of this object, excluding any singleton/meta class in the inheritance chain.Deprecated.untaint(ThreadContext context) rb_obj_untaint call-seq: obj.untaint => obj Removes the taint from obj.untrust(ThreadContext context) Deprecated.untrusted_p(ThreadContext context) Deprecated.private Objectprotected StringDeprecated.protected Stringprotected StringvalidateInstanceVariable(IRubyObject name, String _unused_) Deprecated.protected booleanvariableTableContains(String name) Checks if the variable table contains a variable of the specified name.protected booleanvariableTableFastContains(String internedName) Deprecated.protected ObjectvariableTableFastFetch(String internedName) Deprecated.protected ObjectvariableTableFastStore(String internedName, Object value) Deprecated.protected ObjectvariableTableFetch(String name) Fetch an object from the variable table based on the name.protected ObjectvariableTableRemove(String name) Removes the entry with the specified name from the variable table, and returning the removed value.protected ObjectvariableTableStore(String name, Object value) Store a value in the variable store under the specific name.protected voidvariableTableSync(List<Variable<Object>> vars) Synchronize the variable table with the argument.private voidSerialization of a Ruby (basic) object involves three steps: Dump the object itself Dump a String used to load the appropriate Ruby class Dump each variable from varTable in turn The metaClass field is marked transient since Ruby classes generally will not be able to serialize (since they hold references to method tables, other classes, and potentially thread-, runtime-, or jvm-local state.protected IRubyObjectyieldUnder(ThreadContext context, RubyModule under, Block block, EvalType evalType) Will yield to the specific block changing the self to be the current object instead of the self that is part of the frame saved in the block frame.protected IRubyObjectyieldUnder(ThreadContext context, RubyModule under, IRubyObject[] args, Block block, EvalType evalType) Will yield to the specific block changing the self to be the current object instead of the self that is part of the frame saved in the block frame.
-
Field Details
-
metaClass
The class of this object -
flags
protected int flagsobject flags -
varTable
variable table, lazily allocated as needed (if needed) -
varTableStamp
public transient volatile int varTableStamplocking stamp for Unsafe ops updating the vartable -
VAR_TABLE_OFFSET
public static final long VAR_TABLE_OFFSEToffset of the varTable field in RubyBasicObject -
STAMP_OFFSET
public static final long STAMP_OFFSEToffset of the varTableTamp field in RubyBasicObject -
ERR_INSECURE_SET_INST_VAR
The error message used when some one tries to modify an instance variable in a high security setting.- See Also:
-
ALL_F
public static final int ALL_F- See Also:
-
FALSE_F
public static final int FALSE_F -
NIL_F
public static final int NIL_FThis flag is a bit funny. It's used to denote that this value is nil. It's a bit counterintuitive for a Java programmer to not use subclassing to handle this case, since we have a RubyNil subclass anyway. Well, the reason for it being a flag is that theisNil()method is called extremely often. So often that it gives a good speed boost to make it monomorphic and final. It turns out using a flag for this actually gives us better performance than having a polymorphicisNil()method. -
FROZEN_F
public static final int FROZEN_F -
TAINTED_F
public static final int TAINTED_F -
NEVER
A value that is used as a null sentinel in among other places the RubyArray implementation. It will cause large problems to call any methods on this object. -
UNDEF
A value that specifies an undefined value. This value is used as a sentinel for undefined constant values, and other places where neither null nor NEVER makes sense. -
BASICOBJECT_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:
-
UNTRUST_F
Deprecated.- See Also:
-
FL_USHIFT
Deprecated.- See Also:
-
USER0_F
Deprecated.- See Also:
-
USER1_F
Deprecated.- See Also:
-
USER2_F
Deprecated.- See Also:
-
USER3_F
Deprecated.- See Also:
-
USER4_F
Deprecated.- See Also:
-
USER5_F
Deprecated.- See Also:
-
USER6_F
Deprecated.- See Also:
-
USER7_F
Deprecated.- See Also:
-
USER8_F
Deprecated.- See Also:
-
USER9_F
Deprecated.- See Also:
-
USERA_F
Deprecated.- See Also:
-
REFINED_MODULE_F
Deprecated.- See Also:
-
IS_OVERLAID_F
Deprecated.- See Also:
-
COMPARE_BY_IDENTITY_F
Deprecated.- See Also:
-
-
Constructor Details
-
RubyBasicObject
private RubyBasicObject()It's not valid to create a totally empty RubyObject. Since the RubyObject is always defined in relation to a runtime, that means that creating RubyObjects from outside the class might cause problems. -
RubyBasicObject
Standard path for object creation. Objects are entered into ObjectSpace only if ObjectSpace is enabled. -
RubyBasicObject
Path for objects that don't taint and don't enter objectspace. -
RubyBasicObject
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) -
RubyBasicObject
@Deprecated protected RubyBasicObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted) Deprecated.
-
-
Method Details
-
createBasicObjectClass
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. -
recacheBuiltinMethods
-
initialize
-
initialize19
Deprecated. -
testFrozen
rb_frozen_class_p Helper to test whether this object is frozen, and if it is will throw an exception based on the message. -
testFrozen
protected final void testFrozen()rb_frozen_class_p Helper to test whether this object is frozen, and if it is will throw an exception based on the message. -
setFlag
public final void setFlag(int flag, boolean set) Sets or unsets a flag on this object. The only flags that are guaranteed to be valid to use as the first argument is:- Parameters:
flag- the actual flag to set or unset.set- if true, the flag will be set, if false, the flag will be unset.
-
getFlag
public final boolean getFlag(int flag) Get the value of a custom flag on this object. The only guaranteed flags that can be sent in to this method is:- Parameters:
flag- the flag to get- Returns:
- true if the flag is set, false otherwise
-
checkCallMethod
Will invoke a named method with no arguments and no block if that method or a custom method missing exists. Otherwise returns null. 1.9: rb_check_funcall- Specified by:
checkCallMethodin interfaceIRubyObject
-
checkCallMethod
Will invoke a named method with no arguments and no block if that method or a custom method missing exists. Otherwise returns null. 1.9: rb_check_funcall- Specified by:
checkCallMethodin interfaceIRubyObject
-
callMethod
Will invoke a named method with no arguments and no block.- Specified by:
callMethodin interfaceIRubyObject
-
callMethod
Will invoke a named method with one argument and no block with functional invocation.- Specified by:
callMethodin interfaceIRubyObject
-
callMethod
Will invoke a named method with the supplied arguments and no block with functional invocation.- Specified by:
callMethodin interfaceIRubyObject
-
callMethod
-
callMethod
-
callMethod
-
callMethod
public final IRubyObject callMethod(ThreadContext context, String name, IRubyObject[] args, Block block) Will invoke a named method with the supplied arguments and supplied block with functional invocation.- Specified by:
callMethodin interfaceIRubyObject
-
isNil
public final boolean isNil()Does this object represent nil? See the docs for theNIL_Fflag for more information.- Specified by:
isNilin interfaceIRubyObject- Returns:
- true for
nilonly
-
isTrue
public final boolean isTrue()Is this value a truthy value or not? Based on theFALSE_Fflag.- Specified by:
isTruein interfaceIRubyObject- Returns:
- false for
nilandfalse, true otherwise
-
isFalse
public final boolean isFalse()Is this value a falsey value or not? Based on theFALSE_Fflag. -
isTaint
public boolean isTaint()Gets the taint. Shortcut for getFlag(TAINTED_F).- Specified by:
isTaintin interfaceIRubyObject- Returns:
- true if this object is tainted
-
setTaint
public void setTaint(boolean taint) Sets the taint flag. Shortcut for setFlag(TAINTED_F, taint)- Specified by:
setTaintin interfaceIRubyObject- Parameters:
taint- should this object be tainted or not?
-
infectBy
OBJ_INFECT Infects this object with traits from the argument obj. In real terms this currently means that if obj is tainted, this object will get tainted too. It's possible to hijack this method to do other infections if that would be interesting.- Specified by:
infectByin interfaceIRubyObject- Returns:
- infected (self)
-
infectBy
-
infectBy
-
isFrozen
public boolean isFrozen()Is this value frozen or not? Shortcut for doing getFlag(FROZEN_F).- Specified by:
isFrozenin interfaceIRubyObject- Returns:
- true if this object is frozen, false otherwise
-
setFrozen
public void setFrozen(boolean frozen) Sets whether this object is frozen or not. Shortcut for doing setFlag(FROZEN_F, frozen).- Specified by:
setFrozenin interfaceIRubyObject- Parameters:
frozen- should this object be frozen?
-
isImmediate
public boolean isImmediate()Is object immediate (def: Fixnum, Symbol, true, false, nil?).- Specified by:
isImmediatein interfaceIRubyObject- Returns:
-
isSpecialConst
public boolean isSpecialConst()- Specified by:
isSpecialConstin interfaceIRubyObject- Returns:
-
isSpecialObject
public boolean isSpecialObject() -
getMetaClass
if exist return the meta-class else return the type of the object.- Specified by:
getMetaClassin interfaceIRubyObject- Returns:
- the Ruby (meta) class
-
getMetaClass
-
getSingletonClass
rb_singleton_class Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean Will either return the existing singleton class for this object, or create a new one and return that.- Specified by:
getSingletonClassin interfaceIRubyObject- Returns:
- the Ruby singleton class
-
makeMetaClass
rb_make_metaclass Will create a new meta class, insert this in the chain of classes for this specific object, and return the generated meta class. -
setMetaClass
Makes it possible to change the metaclass of an object. In practice, this is a simple version of Smalltalks Become, except that it doesn't work when we're dealing with subclasses. In practice it's used to change the singleton/meta class used, without changing the "real" inheritance chain. -
getType
Description copied from interface:IRubyObjectRubyMethod getType.- Specified by:
getTypein interfaceIRubyObject- Returns:
- RubyClass
- See Also:
-
respondsTo
Does this object respond to the specified message? Uses a shortcut if it can be proved that respond_to? and respond_to_missing? haven't been overridden.- Specified by:
respondsToin interfaceIRubyObject- Returns:
- boolean
-
respondsToMissing
Does this object respond to the specified message via "method_missing?"- Specified by:
respondsToMissingin interfaceIRubyObject- Returns:
- boolean
-
respondsToMissing
Does this object respond to the specified message via "method_missing?"- Specified by:
respondsToMissingin interfaceIRubyObject- Returns:
- boolean
-
getRuntime
Will return the runtime that this object is associated with.- Specified by:
getRuntimein interfaceIRubyObject- Returns:
- current runtime
-
getJavaClass
Will return the Java interface that most closely can represent this object, when working through Java integration translations.- Specified by:
getJavaClassin interfaceIRubyObject- Returns:
- the true Java class of this (Ruby) object
-
asJavaString
rb_to_id Will try to convert this object to a String using the Ruby "to_str" if the object isn't already a String. If this still doesn't work, will throw a Ruby TypeError.- Specified by:
asJavaStringin interfaceIRubyObject- Returns:
- a (Java) string
-
asString
rb_obj_as_string First converts this object into a String using the "to_s" method, infects it with the current taint and returns it. If to_s doesn't return a Ruby String,anyToString()is used instead.- Specified by:
asStringin interfaceIRubyObject- Returns:
-
convertToArray
Tries to convert this object to a Ruby Array using the "to_ary" method.- Specified by:
convertToArrayin interfaceIRubyObject- Returns:
- array representation of this
-
convertToHash
Tries to convert this object to a Ruby Hash using the "to_hash" method.- Specified by:
convertToHashin interfaceIRubyObject- Returns:
- hash representation of this
-
convertToFloat
Tries to convert this object to a Ruby Float using the "to_f" method.- Specified by:
convertToFloatin interfaceIRubyObject- Returns:
- float representation of this
-
convertToInteger
Tries to convert this object to a Ruby Integer using the "to_int" method.- Specified by:
convertToIntegerin interfaceIRubyObject- Returns:
- an integer representation of this
-
convertToInteger
Tries to convert this object to a Ruby Integer using the supplied conversion method.- Specified by:
convertToIntegerin interfaceIRubyObject- Parameters:
convertMethod- conversion method to use e.g. "to_i"- Returns:
- an integer representation of this
-
convertToString
Tries to convert this object to a Ruby String using the "to_str" method.- Specified by:
convertToStringin interfaceIRubyObject- Returns:
- a string representation of this
-
anyToString
Internal method that helps to convert any object into the format of a class name and a hex string inside of #<>.- Specified by:
anyToStringin interfaceIRubyObject- Returns:
-
decode
raw (id) strings are not properly encoded but in an iso_8859_1 form. This method will lookup properly encoded string from the symbol table. -
checkStringType
rb_check_string_type Tries to return a coerced string representation of this object, using "to_str". If that returns something other than a String or nil, an empty String will be returned.- Specified by:
checkStringTypein interfaceIRubyObject- Returns:
- nil if type check failed
-
checkStringType19
Deprecated.- Specified by:
checkStringType19in interfaceIRubyObject- See Also:
-
checkArrayType
rb_check_array_type Returns the result of trying to convert this object to an Array with "to_ary".- Specified by:
checkArrayTypein interfaceIRubyObject- Returns:
- nil if type check failed
-
toJava
Description copied from interface:IRubyObjectConvert the object to the specified Java class, if possible.- Specified by:
toJavain interfaceIRubyObject- Parameters:
target- The target type to which the object should be converted.- See Also:
-
defaultToJava
-
unwrap_java_object
-
dup
Description copied from interface:IRubyObjectRubyMethod dup.- Specified by:
dupin interfaceIRubyObject- Returns:
- a dup-ed object
-
initCopy
private static IRubyObject initCopy(ThreadContext context, IRubyObject clone, IRubyObject original, boolean doClone) init_copy Initializes a copy with variable and special instance variable information, and then call the initialize_copy Ruby method. -
OBJ_INIT_COPY
-
objInitCopy
-
copySpecialInstanceVariables
Lots of MRI objects keep their state in non-lookupable ivars (e:g. Range, Struct, etc). This method is responsible for dupping our java field equivalents- Specified by:
copySpecialInstanceVariablesin interfaceIRubyObject
-
inspect
rb_inspect The internal helper that ensures a RubyString instance is returned so dangerous casting can be omitted Preferred over callMethod(context, "inspect") -
rbClone
Description copied from interface:IRubyObjectRubyMethod clone.- Specified by:
rbClonein interfaceIRubyObject- Returns:
- a cloned object
-
rbClone
-
rbCloneInternal
-
getSingletonClassClone
-
getSingletonClassCloneAndAttach
rb_singleton_class_clone Will make sure that if the current objects class is a singleton, it will get cloned.- Returns:
- either a real class, or a clone of the current singleton class
-
isModule
public boolean isModule()Specifically polymorphic method that are meant to be overridden by modules to specify that they are modules in an easy way.- Specified by:
isModulein interfaceIRubyObject- Returns:
- true if an object is Ruby Module instance (note that it will return false for Ruby Classes).
If is_a? semantics is required, use
(someObject instanceof RubyModule)instead.
-
isClass
public boolean isClass()Specifically polymorphic method that are meant to be overridden by classes to specify that they are classes in an easy way.- Specified by:
isClassin interfaceIRubyObject- Returns:
- true if an object is Ruby Class instance (note that it will return false for Ruby singleton classes).
If is_a? semantics is required, use
(someObject instanceof RubyClass/MetaClass)instead.
-
dataWrapStruct
Description copied from interface:IRubyObjectOur version of Data_Wrap_Struct. This method will just set a private pointer to the object provided. This pointer is transient and will not be accessible from Ruby.- Specified by:
dataWrapStructin interfaceIRubyObject- Parameters:
obj- the object to wrap- See Also:
-
dataGetStruct
Description copied from interface:IRubyObjectOur version of Data_Get_Struct. Returns a wrapped data value if there is one, otherwise returns null.- Specified by:
dataGetStructin interfaceIRubyObject- Returns:
- the object wrapped.
- See Also:
-
id
rb_obj_id Return the internal id of an object.- Specified by:
idin interfaceIRubyObject- Returns:
- the object id
-
getObjectId
protected long getObjectId()The logic here is to use the special objectId accessor slot from the parent as a lazy store for an object symbol. IDs are generated atomically, in serial, and guaranteed unique for up to 2^63 objects. The special objectId slot is managed separately from the "normal" vars so it does not marshal, clone/dup, or refuse to be initially set when the object is frozen. -
inspect
rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj. If not overridden, uses theto_smethod to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"- Specified by:
inspectin interfaceIRubyObject- Returns:
- String
-
hashyInspect
-
rbInspect
-
inspectHashCode
protected int inspectHashCode()For most objects, the hash used in the default #inspect is just the identity hashcode of the actual object. See org.jruby.java.proxies.JavaProxy for a divergent case.- Returns:
- The identity hashcode of this object
-
inspectObj
inspect_obj The internal helper method that takes care of the part of the inspection that inspects instance variables. -
op_not
-
op_not_equal
The != method implemented for BasicObject.- Parameters:
context- thread contextother- other object- Returns:
- false if this == other, true otherwise
-
compareTo
Compares this Ruby object with another.- Specified by:
compareToin interfaceComparable<IRubyObject>- Parameters:
other- another IRubyObject- Returns:
- 0 if equal, < 0 if this is less than other, > 0 if this is greater than other
-
op_equal
rb_obj_equal Will by default use identity equality to compare objects. This follows the Ruby semantics. The name of this method doesn't follow the convention because hierarchy problems- Specified by:
op_equalin interfaceIRubyObject
-
op_equal_19
Deprecated. -
op_eqq
- Specified by:
op_eqqin interfaceIRubyObject
-
equalInternal
Helper method for checking equality, first using Java identity equality, and then calling the "==" method. -
eql
method used for Hash key comparison (specialized for String, Symbol and Fixnum) Will by default just call the Ruby method "eql?"- Specified by:
eqlin interfaceIRubyObject
-
addFinalizer
Adds the specified object as a finalizer for this object.- Specified by:
addFinalizerin interfaceIRubyObject
-
removeFinalizers
public void removeFinalizers()Remove all the finalizers for this object.- Specified by:
removeFinalizersin interfaceIRubyObject
-
getVariable
- Specified by:
getVariablein interfaceIRubyObject
-
setVariable
- Specified by:
setVariablein interfaceIRubyObject
-
getFFIHandle
-
setFFIHandle
-
hasVariables
public boolean hasVariables()Returns true if object has any variables- Specified by:
hasVariablesin interfaceIRubyObject- Returns:
- true if object has any variables, else false
- See Also:
-
hasInstanceVariables
protected boolean hasInstanceVariables()Check whether this object has any *set* instance variables unrelated to object_id, FFI, and ObjectSpace (which also use hidden ivar slots).- Returns:
- true if there are set instance variables, false otherwise
-
getVariableList
Gets a list of all variables in this object.- Specified by:
getVariableListin interfaceIRubyObject- Returns:
- a list of all variables (ivar/cvar/constant/internal)
-
getVariableNameList
Gets a name list of all variables in this object.- Specified by:
getVariableNameListin interfaceIRubyObject- Returns:
- a list of all variable names (ivar/cvar/constant/internal)
-
variableTableContains
Checks if the variable table contains a variable of the specified name. -
variableTableFetch
Fetch an object from the variable table based on the name.- Returns:
- the object or null if not found
-
variableTableStore
Store a value in the variable store under the specific name. -
variableTableRemove
Removes the entry with the specified name from the variable table, and returning the removed value. -
variableTableSync
Synchronize the variable table with the argument. In real terms this means copy all entries into a newly allocated table. -
getInternalVariables
Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.- Specified by:
getInternalVariablesin interfaceIRubyObject
-
hasInternalVariable
Description copied from interface:InternalVariablesReturns true if object has the named internal variable. Use only for internal variables (not ivar/cvar/constant).- Specified by:
hasInternalVariablein interfaceInternalVariables- Parameters:
name- the name of an internal variable- Returns:
- true if object has the named internal variable.
- See Also:
-
getInternalVariable
Description copied from interface:InternalVariablesReturns the named internal variable if present, else null. Use only for internal variables (not ivar/cvar/constant).- Specified by:
getInternalVariablein interfaceInternalVariables- Parameters:
name- the name of an internal variable- Returns:
- the named internal variable if present, else null
- See Also:
-
setInternalVariable
Description copied from interface:InternalVariablesSets the named internal variable to the specified value. Use only for internal variables (not ivar/cvar/constant).- Specified by:
setInternalVariablein interfaceInternalVariables- Parameters:
name- the name of an internal variablevalue- the value to be set- See Also:
-
removeInternalVariable
Description copied from interface:InternalVariablesRemoves the named internal variable, if present, returning its value. Use only for internal variables (not ivar/cvar/constant).- Specified by:
removeInternalVariablein interfaceInternalVariables- Parameters:
name- the name of the variable to remove- Returns:
- the value of the remove variable, if present; else null
- See Also:
-
syncVariables
Sync one this object's variables with other's - this is used to make rbClone work correctly.- Specified by:
syncVariablesin interfaceIRubyObject- Parameters:
other- the source object containing the variables to sync
-
getInstanceVariables
Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.- Specified by:
getInstanceVariablesin interfaceIRubyObject
-
hasInstanceVariable
Description copied from interface:InstanceVariablesReturns true if object has the named instance variable.- Specified by:
hasInstanceVariablein interfaceInstanceVariables- Parameters:
name- the name of an instance variable- Returns:
- true if object has the named instance variable.
- See Also:
-
getInstanceVariable
Description copied from interface:InstanceVariablesReturns the named instance variable if present, else null.- Specified by:
getInstanceVariablein interfaceInstanceVariables- Parameters:
name- the name of an instance variable- Returns:
- the named instance variable if present, else null
- See Also:
-
setInstanceVariable
rb_iv_set / rb_ivar_set- Specified by:
setInstanceVariablein interfaceInstanceVariables- Parameters:
name- the name of an instance variablevalue- the value to be set- See Also:
-
removeInstanceVariable
Description copied from interface:InstanceVariablesRemoves the named instance variable, if present, returning its value.- Specified by:
removeInstanceVariablein interfaceInstanceVariables- Parameters:
name- the name of the variable to remove- Returns:
- the value of the remove variable, if present; else null
- See Also:
-
getInstanceVariableList
Gets a list of all variables in this object.- Specified by:
getInstanceVariableListin interfaceInstanceVariables- Returns:
- instance variables
-
getInstanceVariableNameList
Gets a name list of all variables in this object.- Specified by:
getInstanceVariableNameListin interfaceInstanceVariables- Returns:
- instance variable names
-
copyInstanceVariablesInto
Description copied from interface:InstanceVariablesCopies all instance variables from the given object into the receiver- Specified by:
copyInstanceVariablesIntoin interfaceInstanceVariables- See Also:
-
ensureInstanceVariablesSettable
public final void ensureInstanceVariablesSettable()Makes sure that instance variables can be set on this object, including information about whether this object is frozen, or tainted. Will throw a suitable exception in that case. -
raiseFrozenError
- Throws:
RaiseException
-
getNativeTypeIndex
Deprecated.Description copied from interface:CoreObjectTypeReturn the ClassIndex value for the native type this object was constructed from. Particularly useful for determining marshalling format. All instances of subclasses of Hash, for example are of Java type RubyHash, and so should utilize RubyHash marshalling logic in addition to user-defined class marshalling logic.- Specified by:
getNativeTypeIndexin interfaceCoreObjectType- Returns:
- the ClassIndex of the native type this object was constructed from
-
getNativeClassIndex
Description copied from interface:CoreObjectTypeReturn the ClassIndex for the native type this object was constructed from.- Specified by:
getNativeClassIndexin interfaceCoreObjectType
-
isBuiltin
A method to determine whether the method named by methodName is a builtin method. This means a method with a JRubyMethod annotation written in Java.- Parameters:
methodName- to look for.- Returns:
- true if so
-
singleton_method_added
public static IRubyObject singleton_method_added(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) -
singleton_method_removed
public static IRubyObject singleton_method_removed(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) -
singleton_method_undefined
public static IRubyObject singleton_method_undefined(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) -
singleton_method_added19
@Deprecated public static IRubyObject singleton_method_added19(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) Deprecated. -
singleton_method_removed19
@Deprecated public static IRubyObject singleton_method_removed19(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) Deprecated. -
singleton_method_undefined19
@Deprecated public static IRubyObject singleton_method_undefined19(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) Deprecated. -
method_missing
public static IRubyObject method_missing(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) -
method_missing19
@Deprecated public static IRubyObject method_missing19(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) Deprecated. -
send
-
send
-
send
public IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) -
send
-
yieldUnder
protected IRubyObject yieldUnder(ThreadContext context, RubyModule under, IRubyObject[] args, Block block, EvalType evalType) Will yield to the specific block changing the self to be the current object instead of the self that is part of the frame saved in the block frame. This method is the basis for the Ruby instance_eval and module_eval methods. The arguments sent in to it in the args array will be yielded to the block. This makes it possible to emulate both instance_eval and instance_exec with this implementation. -
setupBlock
-
yieldUnder
protected IRubyObject yieldUnder(ThreadContext context, RubyModule under, Block block, EvalType evalType) Will yield to the specific block changing the self to be the current object instead of the self that is part of the frame saved in the block frame. This method is the basis for the Ruby instance_eval and module_eval methods. The arguments sent in to it in the args array will be yielded to the block. This makes it possible to emulate both instance_eval and instance_exec with this implementation. -
specificEval
public IRubyObject specificEval(ThreadContext context, RubyModule mod, Block block, EvalType evalType) 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. -
specificEval
public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg, Block block, EvalType evalType) 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. -
specificEval
public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, Block block, EvalType evalType) 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. -
specificEval
public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block, EvalType evalType) 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. -
getInstanceEvalClass
-
evalUnder
public IRubyObject evalUnder(ThreadContext context, RubyModule under, RubyString src, String file, int line, EvalType evalType) Evaluates the string src with self set to the current object, using the module under as the context. -
equal_p
rb_obj_equal Will use Java identity equality. -
equal_p19
Deprecated. -
eql_p
rb_obj_equal Just like "==" and "equal?", "eql?" will use identity equality for Object. -
op_cmp
-
initialize_copy
rb_obj_init_copy Initializes this object as a copy of the original, that is the parameter to this object. Will make sure that the argument actually has the same real class as this object. It shouldn't be possible to initialize an object with something totally different. -
checkFrozen
public void checkFrozen()The actual method that checks frozen with the default frozen message from MRI. If possible, call this instead oftestFrozen(java.lang.String). -
respond_to_p
Deprecated.obj_respond_to respond_to?( aSymbol, includePriv=false ) -> true or false Returns true if this object responds to the given method. Private methods are included in the search only if the optional second parameter evaluates to true.- Returns:
- true if this responds to the given method !!! For some reason MRI shows the arity of respond_to? as -1, when it should be -2; that's why this is rest instead of required, optional = 1 Going back to splitting according to method arity. MRI is wrong about most of these anyway, and since we have arity splitting in both the compiler and the interpreter, the performance benefit is important for this method.
-
respond_to_p19
Deprecated. -
respond_to_p
Deprecated. -
respond_to_p19
Deprecated. -
respond_to_p
final RubyBoolean respond_to_p(ThreadContext context, IRubyObject methodName, boolean includePrivate) -
hash
rb_obj_id Will return the hash code of this object. In comparison to MRI, this method will use the Java identity hash code instead of using rb_obj_id, since the usage of id in JRuby will incur the cost of some. ObjectSpace maintenance. -
type
rb_obj_class Returns the real class of this object, excluding any singleton/meta class in the inheritance chain. -
type_deprecated
Deprecated.rb_obj_type The deprecated version of type, that emits a deprecation warning. -
display
rb_obj_display call-seq: obj.display(port=$>) => nil Prints obj on the given port (default$>). Equivalent to: def display(port=$>) port.write self end For example: 1.display "cat".display [ 4, 5, 6 ].display puts produces: 1cat456 -
tainted_p
rb_obj_tainted call-seq: obj.tainted? => true or false Returnstrueif the object is tainted. -
taint
rb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the$SAFElevel is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings. -
tainted
IRubyObject tainted()Set the object tainted and return it. This version does not check if the object has been frozen or if it is already tainted.- Returns:
-
taint
Deprecated. -
untaint
rb_obj_untaint call-seq: obj.untaint => obj Removes the taint from obj. Only callable in if more secure than 3. -
freeze
rb_obj_freeze call-seq: obj.freeze => obj Prevents further modifications to obj. ATypeErrorwill be raised if modification is attempted. There is no way to unfreeze a frozen object. See alsoObject#frozen?. a = [ "a", "b", "c" ] a.freeze a << "z" produces: prog.rb:3:in `<<': can't modify frozen array (TypeError) from prog.rb:3 -
frozen_p
rb_obj_frozen_p call-seq: obj.frozen? => true or false Returns the freeze status of obj. a = [ "a", "b", "c" ] a.freeze #=> ["a", "b", "c"] a.frozen? #=> true -
instance_of_p
rb_obj_is_instance_of call-seq: obj.instance_of?(class) => true or false Returnstrueif obj is an instance of the given class. See alsoObject#kind_of?. -
kind_of_p
rb_obj_is_kind_of call-seq: obj.is_a?(class) => true or false obj.kind_of?(class) => true or false Returnstrueif class is the class of obj, or if class is one of the superclasses of obj or modules included in obj. module M; end class A include M end class B < A; end class C < B; end b = B.new b.instance_of? A #=> false b.instance_of? B #=> true b.instance_of? C #=> false b.instance_of? M #=> false b.kind_of? A #=> true b.kind_of? B #=> true b.kind_of? C #=> false b.kind_of? M #=> true -
methods
rb_obj_methods call-seq: obj.methods => array Returns a list of the names of methods publicly accessible in obj. This will include all the methods accessible in obj's ancestors. class Klass def kMethod() end end k = Klass.new k.methods[0..9] #=> ["kMethod", "freeze", "nil?", "is_a?", "class", "instance_variable_set", "methods", "extend", "__send__", "instance_eval"] k.methods.length #=> 42 -
methods19
Deprecated. -
methodsImpl
-
methods
@Deprecated public final IRubyObject methods(ThreadContext context, IRubyObject[] args, boolean useSymbols) Deprecated. -
public_methods
rb_obj_public_methods call-seq: obj.public_methods(all=true) => array Returns the list of public methods accessible to obj. If the all parameter is set tofalse, only those methods in the receiver will be listed. -
public_methods19
Deprecated. -
protected_methods
rb_obj_protected_methods call-seq: obj.protected_methods(all=true) => array Returns the list of protected methods accessible to obj. If the all parameter is set tofalse, only those methods in the receiver will be listed. Internally this implementation uses theRubyModule.protected_instance_methods(org.jruby.runtime.builtin.IRubyObject[])method. -
protected_methods19
Deprecated. -
private_methods
rb_obj_private_methods call-seq: obj.private_methods(all=true) => array Returns the list of private methods accessible to obj. If the all parameter is set tofalse, only those methods in the receiver will be listed. Internally this implementation uses theRubyModule.private_instance_methods(org.jruby.runtime.builtin.IRubyObject[])method. -
private_methods19
Deprecated. -
singleton_methods
rb_obj_singleton_methods call-seq: obj.singleton_methods(all=true) => array Returns an array of the names of singleton methods for obj. If the optional all parameter is true, the list will include methods in modules included in obj. module Other def three() end end class Single def Single.four() end end a = Single.new def a.one() end class << a include Other def two() end end Single.singleton_methods #=> ["four"] a.singleton_methods(false) #=> ["two", "one"] a.singleton_methods #=> ["two", "one", "three"] -
singleton_method
-
method
rb_obj_method call-seq: obj.method(sym) => method Looks up the named method as a receiver in obj, returning aMethodobject (or raisingNameError). TheMethodobject acts as a closure in obj's object instance, so instance variables and the value ofselfremain available. class Demo def initialize(n) -
method19
Deprecated. -
to_s
rb_any_to_s call-seq: obj.to_s => string Returns a string representing obj. The defaultto_sprints the object's class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby programs returns ``main.'' -
to_a
rb_any_to_a call-seq: obj.to_a -> anArray Returns an array representation of obj. For objects of classObjectand others that don't explicitly override the method, the return value is an array containingself. However, this latter behavior will soon be obsolete. self.to_a #=> -:1: warning: default `to_a' will be obsolete "hello".to_a #=> ["hello"] Time.new.to_a #=> [39, 54, 8, 9, 4, 2003, 3, 99, true, "CDT"] The default to_a method is deprecated. -
instance_eval
rb_obj_instance_eval call-seq: obj.instance_eval(string [, filename [, lineno]] ) => obj obj.instance_eval {| | block } => obj Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (_obj_). In order to set the context, the variable +self+ is set to _obj_ while the code is executing, giving the code access to _obj_'s instance variables. In the version ofinstance_evalthat takes a +String+, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors. class Klass def initialize -
instance_eval
-
instance_eval
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) -
instance_eval
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) -
instance_eval19
Deprecated. -
instance_eval19
@Deprecated public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, Block block) Deprecated. -
instance_eval19
@Deprecated public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) Deprecated. -
instance_eval19
@Deprecated public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) Deprecated. -
instance_exec
rb_obj_instance_exec call-seq: obj.instance_exec(arg...) {|var...| block } => obj Executes the given block within the context of the receiver (_obj_). In order to set the context, the variable +self+ is set to _obj_ while the code is executing, giving the code access to _obj_'s instance variables. Arguments are passed as block parameters. class Klass def initialize -
instance_exec19
@Deprecated public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Block block) Deprecated. -
extend
rb_obj_extend call-seq: obj.extend(module, ...) => obj Adds to _obj_ the instance methods from each module given as a parameter. module Mod def hello "Hello from Mod.\n" end end class Klass def hello "Hello from Klass.\n" end end k = Klass.new k.hello #=> "Hello from Klass.\n" k.extend(Mod) #=> #<Klass:0x401b3bc8> k.hello #=> "Hello from Mod.\n" -
send
Deprecated.rb_f_send send( aSymbol [, args ]* ) -> anObject Invokes the method identified by aSymbol, passing it any arguments specified. You can use __send__ if the name send clashes with an existing method in this object.class Klass def hello(*args) "Hello " + args.join(' ') end end k = Klass.new k.send :hello, "gentle", "readers"- Returns:
- the result of invoking the method identified by aSymbol.
-
send19
Deprecated. -
send19
@Deprecated public IRubyObject send19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) Deprecated. -
send19
@Deprecated public IRubyObject send19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) Deprecated. -
send19
Deprecated. -
nil_p
rb_false call_seq: nil.nil? => true.nil? => false Only the object nil responds truetonil?. -
op_match
rb_obj_pattern_match call-seq: obj =~ other => nil Pattern Match---Overridden by descendents (notablyRegexpandString) to provide meaningful pattern-match semantics. -
op_not_match
Invert the match operator.- Parameters:
context-arg-- Returns:
-
instance_variable_defined_p
rb_obj_ivar_defined call-seq: obj.instance_variable_defined?(symbol) => true or false Returnstrueif the given instance variable is defined in obj. class Fred def initialize(p1, p2) -
instance_variable_get
rb_obj_ivar_get call-seq: obj.instance_variable_get(symbol) => obj Returns the value of the given instance variable, or nil if the instance variable is not set. The@part of the variable name should be included for regular instance variables. Throws aNameErrorexception if the supplied symbol is not valid as an instance variable name. class Fred def initialize(p1, p2) -
instance_variable_set
rb_obj_ivar_set call-seq: obj.instance_variable_set(symbol, obj) => obj Sets the instance variable names by symbol to object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation. The variable did not have to exist prior to this call. class Fred def initialize(p1, p2) -
remove_instance_variable
rb_obj_remove_instance_variable call-seq: obj.remove_instance_variable(symbol) => obj Removes the named instance variable from obj, returning that variable's value. class Dummy attr_reader :var def initialize -
instance_variables
rb_obj_instance_variables call-seq: obj.instance_variables => array Returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable. class Fred attr_accessor :a1 def initialize -
instance_variables19
Deprecated. -
equals
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. -
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. -
nonFixnumHashCode
-
validateInstanceVariable
Deprecated.Checks if the name parameter represents a legal instance variable name, and otherwise throws a Ruby NameError -
validateInstanceVariable
Deprecated. -
validateInstanceVariable
-
writeObject
Serialization of a Ruby (basic) object involves three steps:- Dump the object itself
- Dump a String used to load the appropriate Ruby class
- Dump each variable from varTable in turn
- Throws:
IOException
-
readObject
Deserialization proceeds as follows:- Deserialize the object instance. It will have null metaClass and varTable fields.
- Deserialize the name of the object's class, and retrieve class from a thread-local JRuby instance.
- Retrieve each variable in turn, re-assigning them by name.
- Throws:
IOExceptionClassNotFoundException- See Also:
-
sites
Retrieve the call sites for this class. It is expected that all Java-based core classes that do call site caching will have a similar method. -
callSuper
Deprecated.- Specified by:
callSuperin interfaceIRubyObject
-
callMethod
@Deprecated public final IRubyObject callMethod(ThreadContext context, int methodIndex, String name) Deprecated.- Specified by:
callMethodin interfaceIRubyObject
-
callMethod
@Deprecated public final IRubyObject callMethod(ThreadContext context, int methodIndex, String name, IRubyObject arg) Deprecated.- Specified by:
callMethodin interfaceIRubyObject
-
convertToInteger
Deprecated.- Specified by:
convertToIntegerin interfaceIRubyObject- See Also:
-
getVariableCount
Deprecated.- Specified by:
getVariableCountin interfaceIRubyObject- Returns:
- the count of all variables (ivar/cvar/constant/internal)
-
variableTableFastContains
Deprecated. -
variableTableFastFetch
Deprecated. -
variableTableFastStore
Deprecated. -
fastHasInternalVariable
Deprecated.- Specified by:
fastHasInternalVariablein interfaceInternalVariables
-
fastGetInternalVariable
Deprecated.- Specified by:
fastGetInternalVariablein interfaceInternalVariables
-
fastSetInternalVariable
Deprecated.- Specified by:
fastSetInternalVariablein interfaceInternalVariables
-
syncVariables
Deprecated.Description copied from interface:IRubyObjectSets object's variables to those in the supplied list, removing/replacing any previously defined variables. Applies to all variable types (ivar/cvar/constant/internal).- Specified by:
syncVariablesin interfaceIRubyObject- Parameters:
variables- the variables to be set for object
-
fastHasInstanceVariable
Deprecated.- Specified by:
fastHasInstanceVariablein interfaceInstanceVariables
-
fastGetInstanceVariable
Deprecated.- Specified by:
fastGetInstanceVariablein interfaceInstanceVariables
-
fastSetInstanceVariable
Deprecated.- Specified by:
fastSetInstanceVariablein interfaceInstanceVariables
-
isUntrusted
Deprecated.Description copied from interface:IRubyObjectRubyMethod isUntrusted.- Specified by:
isUntrustedin interfaceIRubyObject- Returns:
- boolean
-
setUntrusted
Deprecated.Description copied from interface:IRubyObjectRubyMethod setUntrusted.- Specified by:
setUntrustedin interfaceIRubyObject
-
untrusted_p
Deprecated. -
untrust
Deprecated. -
trust
Deprecated. -
getNativeHandle
Deprecated. -
setNativeHandle
Deprecated. -
dataGetStructChecked
Deprecated.- Specified by:
dataGetStructCheckedin interfaceIRubyObject
-
op_match19
Deprecated. -
to_a
Deprecated.
-