org.jruby
Class RubyBasicObject

java.lang.Object
  extended by org.jruby.RubyBasicObject
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType
Direct Known Subclasses:
RubyObject

public class RubyBasicObject
extends java.lang.Object
implements java.lang.Cloneable, IRubyObject, java.io.Serializable, CoreObjectType, InstanceVariables, InternalVariables

Author:
enebo
See Also:
Serialized Form

Nested Class Summary
static class RubyBasicObject.BasicObjectMethods
          Interestingly, the Object class doesn't really have that many methods for itself.
 class RubyBasicObject.Finalizer
          Class that keeps track of the finalizers for the object under operation.
protected static class RubyBasicObject.VariableTableEntry
          Every entry in the variable map is represented by an instance of this class.
 
Field Summary
static int ALL_F
           
protected  java.lang.Object dataStruct
           
protected static java.lang.String ERR_INSECURE_SET_INST_VAR
          The error message used when some one tries to modify an instance variable in a high security setting.
static int FALSE_F
           
static int FL_USHIFT
           
protected  int flags
           
static int FROZEN_F
           
protected  RubyClass metaClass
           
static IRubyObject NEVER
          A value that is used as a null sentinel in among other places the RubyArray implementation.
static int NIL_F
          This flag is a bit funny.
static ObjectAllocator OBJECT_ALLOCATOR
          Default allocator instance for all Ruby objects.
static int TAINTED_F
           
static IRubyObject UNDEF
          A value that specifies an undefined value.
static int USER0_F
           
static int USER1_F
           
static int USER2_F
           
static int USER3_F
           
static int USER4_F
           
static int USER5_F
           
static int USER6_F
           
static int USER7_F
           
protected static int VARIABLE_TABLE_DEFAULT_CAPACITY
           
protected static RubyBasicObject.VariableTableEntry[] VARIABLE_TABLE_EMPTY_TABLE
           
protected static float VARIABLE_TABLE_LOAD_FACTOR
           
protected static int VARIABLE_TABLE_MAXIMUM_CAPACITY
           
protected  RubyBasicObject.VariableTableEntry[] variableTable
          The variableTable contains variables for an object, defined as: instance variables class variables (for classes/modules) internal variables (such as those used when marshaling RubyRange and RubyException) Constants are stored separately, see RubyModule.
protected  int variableTableSize
           
protected  int variableTableThreshold
           
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
  RubyBasicObject(Ruby runtime, RubyClass metaClass)
          Standard path for object creation.
protected RubyBasicObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace)
           
protected RubyBasicObject(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 addFinalizer(IRubyObject finalizer)
          Adds the specified object as a finalizer for this object.
 IRubyObject anyToString()
          Internal method that helps to convert any object into the format of a class name and a hex string inside of #<>.
 java.lang.String 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.
 RubyString 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.
 IRubyObject callMethod(ThreadContext context, int methodIndex, java.lang.String name)
          Deprecated. 
 IRubyObject callMethod(ThreadContext context, int methodIndex, java.lang.String name, IRubyObject arg)
          Deprecated. 
 IRubyObject callMethod(ThreadContext context, java.lang.String name)
          Will invoke a named method with no arguments and no block.
 IRubyObject callMethod(ThreadContext context, java.lang.String name, IRubyObject arg)
          Will invoke a named method with one argument and no block with functional invocation.
 IRubyObject callMethod(ThreadContext context, java.lang.String name, IRubyObject[] args)
          Will invoke a named method with the supplied arguments and no block with functional invocation.
 IRubyObject callMethod(ThreadContext context, java.lang.String name, IRubyObject[] args, Block block)
          Will invoke a named method with the supplied arguments and supplied block with functional invocation.
 IRubyObject callSuper(ThreadContext context, IRubyObject[] args, Block block)
          Deprecated. 
 IRubyObject checkArrayType()
          rb_check_array_type Returns the result of trying to convert this object to an Array with "to_ary".
 IRubyObject checkStringType()
          rb_check_string_type Tries to return a coerced string representation of this object, using "to_str".
 RubyArray convertToArray()
          Tries to convert this object to a Ruby Array using the "to_ary" method.
 RubyFloat convertToFloat()
          Tries to convert this object to a Ruby Float using the "to_f" method.
 RubyHash convertToHash()
          Tries to convert this object to a Ruby Hash using the "to_hash" method.
 RubyInteger convertToInteger()
          Tries to convert this object to a Ruby Integer using the "to_int" method.
 RubyInteger convertToInteger(int methodIndex, java.lang.String convertMethod)
          Deprecated. 
 RubyInteger convertToInteger(java.lang.String convertMethod)
          Tries to convert this object to a Ruby Integer using the supplied conversion method.
 RubyString convertToString()
          Tries to convert this object to a Ruby String using the "to_str" method.
 void copyInstanceVariablesInto(InstanceVariables other)
          Copies all instance variables from the given object into the receiver
 void copySpecialInstanceVariables(IRubyObject clone)
          Lots of MRI objects keep their state in non-lookupable ivars (e:g.
static RubyClass createBasicObjectClass(Ruby runtime, RubyClass objectClass)
          Will create the Ruby class Object in the runtime specified.
 java.lang.Object dataGetStruct()
          Our version of Data_Get_Struct.
 void dataWrapStruct(java.lang.Object obj)
          Our version of Data_Wrap_Struct.
 IRubyObject dup()
          RubyMethod dup.
protected  void ensureInstanceVariablesSettable()
          Makes sure that instance variables can be set on this object, including information about whether this object is frozen, or tainted.
 boolean eql(IRubyObject other)
          method used for Hash key comparison (specialized for String, Symbol and Fixnum) Will by default just call the Ruby method "eql?"
protected static boolean equalInternal(ThreadContext context, IRubyObject that, IRubyObject other)
          Helper method for checking equality, first using Java identity equality, and then calling the "==" method.
 IRubyObject fastGetInstanceVariable(java.lang.String internedName)
          Returns the named instance variable if present, else null.
 IRubyObject fastGetInternalVariable(java.lang.String internedName)
          Returns the named internal variable if present, else null.
 boolean fastHasInstanceVariable(java.lang.String internedName)
          Returns true if object has the named instance variable.
 boolean fastHasInternalVariable(java.lang.String internedName)
          Returns true if object has the named internal variable.
 IRubyObject fastSetInstanceVariable(java.lang.String internedName, IRubyObject value)
          Sets the named instance variable to the specified value.
 void fastSetInternalVariable(java.lang.String internedName, IRubyObject value)
          Sets the named internal variable to the specified value.
 boolean getFlag(int flag)
          Get the value of a custom flag on this object.
 IRubyObject getInstanceVariable(java.lang.String name)
          Returns the named instance variable if present, else null.
 java.util.List<Variable<IRubyObject>> getInstanceVariableList()
           
 java.util.List<java.lang.String> getInstanceVariableNameList()
           
 InstanceVariables getInstanceVariables()
          Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.
 IRubyObject getInternalVariable(java.lang.String name)
          Returns the named internal variable if present, else null.
 java.util.List<Variable<IRubyObject>> getInternalVariableList()
           
 InternalVariables getInternalVariables()
          Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.
 java.lang.Class getJavaClass()
          Will return the Java interface that most closely can represent this object, when working through JAva integration translations.
 RubyClass getMetaClass()
          if exist return the meta-class else return the type of the object.
 int getNativeTypeIndex()
          Return the ClassIndex value for the native type this object was constructed from.
 Ruby getRuntime()
          Will return the runtime that this object is associated with.
 RubyClass 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.
protected  RubyClass getSingletonClassClone()
          rb_singleton_class_clone Will make sure that if the current objects class is a singleton, it will get cloned.
 RubyClass getType()
          RubyMethod getType.
 int getVariableCount()
          Returns the amount of instance variables, class variables, constants and internal variables this object has.
 java.util.List<Variable<IRubyObject>> getVariableList()
          Gets a list of all variables in this object.
 java.util.Map getVariableMap()
          Deprecated. 
 java.util.List<java.lang.String> getVariableNameList()
          Gets a name list of all variables in this object.
 boolean hasInstanceVariable(java.lang.String name)
          Returns true if object has the named instance variable.
 boolean hasInternalVariable(java.lang.String name)
          Returns true if object has the named internal variable.
 boolean hasVariables()
          Returns true if object has any variables, defined as: instance variables class variables constants internal variables, such as those used when marshaling Ranges and Exceptions
 IRubyObject id()
          rb_obj_id Return the internal id of an object.
 IRubyObject infectBy(IRubyObject obj)
          OBJ_INFECT Infects this object with traits from the argument obj.
 IRubyObject inspect()
          rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj.
 boolean isClass()
          Specifically polymorphic method that are meant to be overridden by classes to specify that they are classes in an easy way.
 boolean isFalse()
          Is this value a false value or not? Based on the FALSE_F flag.
 boolean isFrozen()
          Is this value frozen or not? Shortcut for doing getFlag(FROZEN_F).
 boolean isImmediate()
          Is object immediate (def: Fixnum, Symbol, true, false, nil?).
 boolean isModule()
          Specifically polymorphic method that are meant to be overridden by modules to specify that they are modules in an easy way.
 boolean isNil()
          Does this object represent nil? See the docs for the NIL_F flag for more information.
protected static boolean isRubyVariable(java.lang.String name)
          Check the syntax of a Ruby variable, including that it's longer than zero characters, and starts with either an @ or a capital letter.
 boolean isTaint()
          Gets the taint.
 boolean isTrue()
          Is this value a true value or not? Based on the FALSE_F flag.
 RubyClass 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.
 IRubyObject op_eqq(ThreadContext context, IRubyObject other)
          rb_equal The Ruby "===" method is used by default in case/when statements.
 IRubyObject op_equal(ThreadContext context, IRubyObject obj)
          rb_obj_equal Will by default use identity equality to compare objects.
 IRubyObject op_not_equal(ThreadContext context, IRubyObject other)
           
 IRubyObject op_not(ThreadContext context)
           
 IRubyObject rbClone()
          RubyMethod rbClone.
 void removeFinalizers()
          Remove all the finalizers for this object.
 IRubyObject removeInstanceVariable(java.lang.String name)
          Removes the named instance variable, if present, returning its value.
 IRubyObject removeInternalVariable(java.lang.String name)
          Removes the named internal variable, if present, returning its value.
 boolean respondsTo(java.lang.String name)
          Does this object respond to the specified message? Uses a shortcut if it can be proved that respond_to? haven't been overridden.
 void setFlag(int flag, boolean set)
          Sets or unsets a flag on this object.
 void setFrozen(boolean frozen)
          Sets whether this object is frozen or not.
 IRubyObject setInstanceVariable(java.lang.String name, IRubyObject value)
          rb_iv_set / rb_ivar_set
 void setInternalVariable(java.lang.String name, IRubyObject value)
          Sets the named internal variable to the specified value.
 void setMetaClass(RubyClass metaClass)
          Makes it possible to change the metaclass of an object.
 void setTaint(boolean taint)
          Sets the taint flag.
 void syncVariables(java.util.List<Variable<IRubyObject>> variables)
          Sync one variable table with another - this is used to make rbClone work correctly.
protected  void taint(Ruby runtime)
           
protected  void testFrozen(java.lang.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.
protected  boolean variableTableContains(java.lang.String name)
          Checks if the variable table contains a variable of the specified name.
protected  boolean variableTableFastContains(java.lang.String internedName)
          Checks if the variable table contains the the variable of the specified name, where the precondition is that the name must be an interned Java String.
protected  IRubyObject variableTableFastFetch(java.lang.String internedName)
          Fetch an object from the variable table based on the name, where the name must be an interned Java String.
protected  IRubyObject variableTableFastStore(java.lang.String internedName, IRubyObject value)
          Will store the value under the specified name, where the name needs to be an interned Java String.
protected  IRubyObject variableTableFetch(java.lang.String name)
          Fetch an object from the variable table based on the name.
protected  java.util.Map variableTableGetMap()
          Method to help ease transition to new variables implementation.
protected  java.util.Map variableTableGetMap(java.util.Map map)
          Method to help ease transition to new variables implementation.
protected  int variableTableGetSize()
          Get the size of the variable table.
protected  RubyBasicObject.VariableTableEntry[] variableTableGetTable()
          Get the actual table used to save variable entries.
protected  IRubyObject variableTableReadLocked(RubyBasicObject.VariableTableEntry entry)
          Reads the value of the specified entry, locked on the current object.
protected  RubyBasicObject.VariableTableEntry[] variableTableRehash()
          Rehashes the variable table.
protected  IRubyObject variableTableRemove(java.lang.String name)
          Removes the entry with the specified name from the variable table, and returning the removed value.
protected  IRubyObject variableTableStore(java.lang.String name, IRubyObject value)
          Store a value in the variable store under the specific name.
protected  void variableTableSync(java.util.List<Variable<IRubyObject>> vars)
          Synchronize the variable table with the argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

metaClass

protected transient RubyClass metaClass

flags

protected int flags

dataStruct

protected transient java.lang.Object dataStruct

variableTable

protected transient volatile RubyBasicObject.VariableTableEntry[] variableTable
The variableTable contains variables for an object, defined as: Constants are stored separately, see RubyModule.


variableTableSize

protected transient int variableTableSize

variableTableThreshold

protected transient int variableTableThreshold

ERR_INSECURE_SET_INST_VAR

protected static final java.lang.String 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:
Constant Field Values

ALL_F

public static final int ALL_F
See Also:
Constant Field Values

FALSE_F

public static final int FALSE_F
See Also:
Constant Field Values

NIL_F

public static final int NIL_F
This 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 the isNil() 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 polymorphic isNil() method.

See Also:
Constant Field Values

FROZEN_F

public static final int FROZEN_F
See Also:
Constant Field Values

TAINTED_F

public static final int TAINTED_F
See Also:
Constant Field Values

FL_USHIFT

public static final int FL_USHIFT
See Also:
Constant Field Values

USER0_F

public static final int USER0_F
See Also:
Constant Field Values

USER1_F

public static final int USER1_F
See Also:
Constant Field Values

USER2_F

public static final int USER2_F
See Also:
Constant Field Values

USER3_F

public static final int USER3_F
See Also:
Constant Field Values

USER4_F

public static final int USER4_F
See Also:
Constant Field Values

USER5_F

public static final int USER5_F
See Also:
Constant Field Values

USER6_F

public static final int USER6_F
See Also:
Constant Field Values

USER7_F

public static final int USER7_F
See Also:
Constant Field Values

NEVER

public static final IRubyObject 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

public static final IRubyObject 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.


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

VARIABLE_TABLE_DEFAULT_CAPACITY

protected static final int VARIABLE_TABLE_DEFAULT_CAPACITY
See Also:
Constant Field Values

VARIABLE_TABLE_MAXIMUM_CAPACITY

protected static final int VARIABLE_TABLE_MAXIMUM_CAPACITY
See Also:
Constant Field Values

VARIABLE_TABLE_LOAD_FACTOR

protected static final float VARIABLE_TABLE_LOAD_FACTOR
See Also:
Constant Field Values

VARIABLE_TABLE_EMPTY_TABLE

protected static final RubyBasicObject.VariableTableEntry[] VARIABLE_TABLE_EMPTY_TABLE
Constructor Detail

RubyBasicObject

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


RubyBasicObject

protected RubyBasicObject(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)


RubyBasicObject

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

createBasicObjectClass

public static RubyClass createBasicObjectClass(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.


taint

protected void taint(Ruby runtime)

testFrozen

protected final void testFrozen(java.lang.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.


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

callSuper

@Deprecated
public IRubyObject callSuper(ThreadContext context,
                                        IRubyObject[] args,
                                        Block block)
Deprecated. 

See org.jruby.javasupport.util.RuntimeHelpers#invokeSuper

Specified by:
callSuper in interface IRubyObject

callMethod

public final IRubyObject callMethod(ThreadContext context,
                                    java.lang.String name)
Will invoke a named method with no arguments and no block.

Specified by:
callMethod in interface IRubyObject

callMethod

public final IRubyObject callMethod(ThreadContext context,
                                    java.lang.String name,
                                    IRubyObject arg)
Will invoke a named method with one argument and no block with functional invocation.

Specified by:
callMethod in interface IRubyObject

callMethod

public final IRubyObject callMethod(ThreadContext context,
                                    java.lang.String name,
                                    IRubyObject[] args)
Will invoke a named method with the supplied arguments and no block with functional invocation.

Specified by:
callMethod in interface IRubyObject

callMethod

public final IRubyObject callMethod(ThreadContext context,
                                    java.lang.String name,
                                    IRubyObject[] args,
                                    Block block)
Will invoke a named method with the supplied arguments and supplied block with functional invocation.

Specified by:
callMethod in interface IRubyObject

callMethod

@Deprecated
public final IRubyObject callMethod(ThreadContext context,
                                               int methodIndex,
                                               java.lang.String name)
Deprecated. 

Will invoke an indexed method with the no arguments and no block.

Specified by:
callMethod in interface IRubyObject

callMethod

@Deprecated
public final IRubyObject callMethod(ThreadContext context,
                                               int methodIndex,
                                               java.lang.String name,
                                               IRubyObject arg)
Deprecated. 

Will invoke an indexed method with the one argument and no block with a functional invocation.

Specified by:
callMethod in interface IRubyObject

isNil

public final boolean isNil()
Does this object represent nil? See the docs for the NIL_F flag for more information.

Specified by:
isNil in interface IRubyObject
Returns:
boolean

isTrue

public final boolean isTrue()
Is this value a true value or not? Based on the FALSE_F flag.

Specified by:
isTrue in interface IRubyObject
Returns:

isFalse

public final boolean isFalse()
Is this value a false value or not? Based on the FALSE_F flag.


isTaint

public boolean isTaint()
Gets the taint. Shortcut for getFlag(TAINTED_F).

Specified by:
isTaint in interface IRubyObject
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:
setTaint in interface IRubyObject
Parameters:
taint - should this object be tainted or not?

infectBy

public IRubyObject infectBy(IRubyObject obj)
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:
infectBy in interface IRubyObject
Returns:

isFrozen

public boolean isFrozen()
Is this value frozen or not? Shortcut for doing getFlag(FROZEN_F).

Specified by:
isFrozen in interface IRubyObject
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:
setFrozen in interface IRubyObject
Parameters:
frozen - should this object be frozen?

isImmediate

public boolean isImmediate()
Is object immediate (def: Fixnum, Symbol, true, false, nil?).

Specified by:
isImmediate in interface IRubyObject
Returns:

getMetaClass

public final RubyClass getMetaClass()
if exist return the meta-class else return the type of the object.

Specified by:
getMetaClass in interface IRubyObject
Returns:

getSingletonClass

public RubyClass 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:
getSingletonClass in interface IRubyObject
Returns:
RubyClass

makeMetaClass

public RubyClass 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.


setMetaClass

public void setMetaClass(RubyClass metaClass)
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

public RubyClass getType()
Description copied from interface: IRubyObject
RubyMethod getType.

Specified by:
getType in interface IRubyObject
Returns:
RubyClass
See Also:
IRubyObject.getType()

respondsTo

public final boolean respondsTo(java.lang.String name)
Does this object respond to the specified message? Uses a shortcut if it can be proved that respond_to? haven't been overridden.

Specified by:
respondsTo in interface IRubyObject
Returns:
boolean

getRuntime

public final Ruby getRuntime()
Will return the runtime that this object is associated with.

Specified by:
getRuntime in interface IRubyObject
Returns:
current runtime

getJavaClass

public java.lang.Class getJavaClass()
Will return the Java interface that most closely can represent this object, when working through JAva integration translations.

Specified by:
getJavaClass in interface IRubyObject
Returns:
Class

asJavaString

public java.lang.String 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:
asJavaString in interface IRubyObject
Returns:
String the symbol name

asString

public RubyString 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:
asString in interface IRubyObject
Returns:

convertToArray

public RubyArray convertToArray()
Tries to convert this object to a Ruby Array using the "to_ary" method.

Specified by:
convertToArray in interface IRubyObject
Returns:

convertToHash

public RubyHash convertToHash()
Tries to convert this object to a Ruby Hash using the "to_hash" method.

Specified by:
convertToHash in interface IRubyObject
Returns:

convertToFloat

public RubyFloat convertToFloat()
Tries to convert this object to a Ruby Float using the "to_f" method.

Specified by:
convertToFloat in interface IRubyObject
Returns:

convertToInteger

public RubyInteger convertToInteger()
Tries to convert this object to a Ruby Integer using the "to_int" method.

Specified by:
convertToInteger in interface IRubyObject
Returns:

convertToInteger

@Deprecated
public RubyInteger convertToInteger(int methodIndex,
                                               java.lang.String convertMethod)
Deprecated. 

Specified by:
convertToInteger in interface IRubyObject
Returns:

convertToInteger

public RubyInteger convertToInteger(java.lang.String convertMethod)
Tries to convert this object to a Ruby Integer using the supplied conversion method.

Specified by:
convertToInteger in interface IRubyObject
Returns:

convertToString

public RubyString convertToString()
Tries to convert this object to a Ruby String using the "to_str" method.

Specified by:
convertToString in interface IRubyObject
Returns:

anyToString

public IRubyObject anyToString()
Internal method that helps to convert any object into the format of a class name and a hex string inside of #<>.

Specified by:
anyToString in interface IRubyObject
Returns:

checkStringType

public IRubyObject 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:
checkStringType in interface IRubyObject
Returns:

checkArrayType

public IRubyObject checkArrayType()
rb_check_array_type Returns the result of trying to convert this object to an Array with "to_ary".

Specified by:
checkArrayType in interface IRubyObject
Returns:

dup

public IRubyObject dup()
Description copied from interface: IRubyObject
RubyMethod dup.

Specified by:
dup in interface IRubyObject
Returns:

copySpecialInstanceVariables

public void copySpecialInstanceVariables(IRubyObject clone)
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:
copySpecialInstanceVariables in interface IRubyObject

rbClone

public IRubyObject rbClone()
Description copied from interface: IRubyObject
RubyMethod rbClone.

Specified by:
rbClone in interface IRubyObject
Returns:
IRubyObject

getSingletonClassClone

protected RubyClass getSingletonClassClone()
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:
isModule in interface IRubyObject
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:
isClass in interface IRubyObject
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

public void dataWrapStruct(java.lang.Object obj)
Description copied from interface: IRubyObject
Our 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:
dataWrapStruct in interface IRubyObject
Parameters:
obj - the object to wrap
See Also:
org.jruby.runtime.builtin.IRubyObject#dataWrapStruct()

dataGetStruct

public java.lang.Object dataGetStruct()
Description copied from interface: IRubyObject
Our version of Data_Get_Struct. Returns a wrapped data value if there is one, otherwise returns null.

Specified by:
dataGetStruct in interface IRubyObject
Returns:
the object wrapped.
See Also:
IRubyObject.dataGetStruct()

id

public IRubyObject id()
rb_obj_id Return the internal id of an object. FIXME: Should this be renamed to match its ruby name?

Specified by:
id in interface IRubyObject
Returns:

inspect

public IRubyObject inspect()
rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj. If not overridden, uses the to_s method 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:
inspect in interface IRubyObject
Returns:
String

op_not

public IRubyObject op_not(ThreadContext context)

op_not_equal

public IRubyObject op_not_equal(ThreadContext context,
                                IRubyObject other)

op_equal

public IRubyObject op_equal(ThreadContext context,
                            IRubyObject obj)
rb_obj_equal Will by default use identity equality to compare objects. This follows the Ruby semantics.

Specified by:
op_equal in interface IRubyObject

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

equalInternal

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


eql

public boolean eql(IRubyObject other)
method used for Hash key comparison (specialized for String, Symbol and Fixnum) Will by default just call the Ruby method "eql?"

Specified by:
eql in interface IRubyObject

addFinalizer

public void addFinalizer(IRubyObject finalizer)
Adds the specified object as a finalizer for this object.

Specified by:
addFinalizer in interface IRubyObject

removeFinalizers

public void removeFinalizers()
Remove all the finalizers for this object.

Specified by:
removeFinalizers in interface IRubyObject

hasVariables

public boolean hasVariables()
Returns true if object has any variables, defined as:

Specified by:
hasVariables in interface IRubyObject
Returns:
true if object has any variables, else false

getVariableCount

public int getVariableCount()
Returns the amount of instance variables, class variables, constants and internal variables this object has.

Specified by:
getVariableCount in interface IRubyObject
Returns:
the count of all variables (ivar/cvar/constant/internal)

getVariableList

public java.util.List<Variable<IRubyObject>> getVariableList()
Gets a list of all variables in this object.

Specified by:
getVariableList in interface IRubyObject
Returns:
a list of all variables (ivar/cvar/constant/internal)

getVariableNameList

public java.util.List<java.lang.String> getVariableNameList()
Gets a name list of all variables in this object.

Specified by:
getVariableNameList in interface IRubyObject
Returns:
a list of all variable names (ivar/cvar/constant/internal)

getVariableMap

@Deprecated
public java.util.Map getVariableMap()
Deprecated. 

Gets internal access to the getmap for variables.


isRubyVariable

protected static final boolean isRubyVariable(java.lang.String name)
Check the syntax of a Ruby variable, including that it's longer than zero characters, and starts with either an @ or a capital letter.


variableTableReadLocked

protected IRubyObject variableTableReadLocked(RubyBasicObject.VariableTableEntry entry)
Reads the value of the specified entry, locked on the current object.


variableTableContains

protected boolean variableTableContains(java.lang.String name)
Checks if the variable table contains a variable of the specified name.


variableTableFastContains

protected boolean variableTableFastContains(java.lang.String internedName)
Checks if the variable table contains the the variable of the specified name, where the precondition is that the name must be an interned Java String.


variableTableFetch

protected IRubyObject variableTableFetch(java.lang.String name)
Fetch an object from the variable table based on the name.

Returns:
the object or null if not found

variableTableFastFetch

protected IRubyObject variableTableFastFetch(java.lang.String internedName)
Fetch an object from the variable table based on the name, where the name must be an interned Java String.

Returns:
the object or null if not found

variableTableStore

protected IRubyObject variableTableStore(java.lang.String name,
                                         IRubyObject value)
Store a value in the variable store under the specific name.


variableTableFastStore

protected IRubyObject variableTableFastStore(java.lang.String internedName,
                                             IRubyObject value)
Will store the value under the specified name, where the name needs to be an interned Java String.


variableTableRemove

protected IRubyObject variableTableRemove(java.lang.String name)
Removes the entry with the specified name from the variable table, and returning the removed value.


variableTableGetTable

protected RubyBasicObject.VariableTableEntry[] variableTableGetTable()
Get the actual table used to save variable entries.


variableTableGetSize

protected int variableTableGetSize()
Get the size of the variable table.


variableTableSync

protected void variableTableSync(java.util.List<Variable<IRubyObject>> vars)
Synchronize the variable table with the argument. In real terms this means copy all entries into a newly allocated table.


variableTableRehash

protected final RubyBasicObject.VariableTableEntry[] variableTableRehash()
Rehashes the variable table. Must be called from a synchronized block.


variableTableGetMap

protected java.util.Map variableTableGetMap()
Method to help ease transition to new variables implementation. Will likely be deprecated in the near future.


variableTableGetMap

protected java.util.Map variableTableGetMap(java.util.Map map)
Method to help ease transition to new variables implementation. Will likely be deprecated in the near future.


getInternalVariables

public InternalVariables getInternalVariables()
Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.

Specified by:
getInternalVariables in interface IRubyObject

hasInternalVariable

public boolean hasInternalVariable(java.lang.String name)
Description copied from interface: InternalVariables
Returns true if object has the named internal variable. Use only for internal variables (not ivar/cvar/constant).

Specified by:
hasInternalVariable in interface InternalVariables
Parameters:
name - the name of an internal variable
Returns:
true if object has the named internal variable.
See Also:
InternalVariables.hasInternalVariable(java.lang.String)

fastHasInternalVariable

public boolean fastHasInternalVariable(java.lang.String internedName)
Description copied from interface: InternalVariables
Returns true if object has the named internal variable. Use only for internal variables (not ivar/cvar/constant). The supplied name must have been previously interned.

Specified by:
fastHasInternalVariable in interface InternalVariables
Parameters:
internedName - the interned name of an internal variable
Returns:
true if object has the named internal variable, else false
See Also:
InternalVariables.fastHasInternalVariable(java.lang.String)

getInternalVariable

public IRubyObject getInternalVariable(java.lang.String name)
Description copied from interface: InternalVariables
Returns the named internal variable if present, else null. Use only for internal variables (not ivar/cvar/constant).

Specified by:
getInternalVariable in interface InternalVariables
Parameters:
name - the name of an internal variable
Returns:
the named internal variable if present, else null
See Also:
InternalVariables.getInternalVariable(java.lang.String)

fastGetInternalVariable

public IRubyObject fastGetInternalVariable(java.lang.String internedName)
Description copied from interface: InternalVariables
Returns the named internal variable if present, else null. Use only for internal variables (not ivar/cvar/constant). The supplied name must have been previously interned.

Specified by:
fastGetInternalVariable in interface InternalVariables
Parameters:
internedName - the interned name of an internal variable
Returns:
he named internal variable if present, else null
See Also:
InternalVariables.fastGetInternalVariable(java.lang.String)

setInternalVariable

public void setInternalVariable(java.lang.String name,
                                IRubyObject value)
Description copied from interface: InternalVariables
Sets the named internal variable to the specified value. Use only for internal variables (not ivar/cvar/constant).

Specified by:
setInternalVariable in interface InternalVariables
Parameters:
name - the name of an internal variable
value - the value to be set
See Also:
InternalVariables.setInternalVariable(java.lang.String, org.jruby.runtime.builtin.IRubyObject)

fastSetInternalVariable

public void fastSetInternalVariable(java.lang.String internedName,
                                    IRubyObject value)
Description copied from interface: InternalVariables
Sets the named internal variable to the specified value. Use only for internal variables (not ivar/cvar/constant). The supplied name must have been previously interned.

Specified by:
fastSetInternalVariable in interface InternalVariables
Parameters:
internedName - the interned name of an internal variable
value - the value to be set
See Also:
InternalVariables.fastSetInternalVariable(java.lang.String, org.jruby.runtime.builtin.IRubyObject)

removeInternalVariable

public IRubyObject removeInternalVariable(java.lang.String name)
Description copied from interface: InternalVariables
Removes the named internal variable, if present, returning its value. Use only for internal variables (not ivar/cvar/constant).

Specified by:
removeInternalVariable in interface InternalVariables
Parameters:
name - the name of the variable to remove
Returns:
the value of the remove variable, if present; else null
See Also:
InternalVariables.removeInternalVariable(java.lang.String)

syncVariables

public void syncVariables(java.util.List<Variable<IRubyObject>> variables)
Sync one variable table with another - this is used to make rbClone work correctly.

Specified by:
syncVariables in interface IRubyObject
Parameters:
variables - the variables to be set for object

getInternalVariableList

public java.util.List<Variable<IRubyObject>> getInternalVariableList()
Specified by:
getInternalVariableList in interface InternalVariables
Returns:
only internal variables (NOT ivar/cvar/constant)
See Also:
InternalVariables.getInternalVariableList()

getInstanceVariables

public InstanceVariables getInstanceVariables()
Dummy method to avoid a cast, and to avoid polluting the IRubyObject interface with all the instance variable management methods.

Specified by:
getInstanceVariables in interface IRubyObject

hasInstanceVariable

public boolean hasInstanceVariable(java.lang.String name)
Description copied from interface: InstanceVariables
Returns true if object has the named instance variable.

Specified by:
hasInstanceVariable in interface InstanceVariables
Parameters:
name - the name of an instance variable
Returns:
true if object has the named instance variable.
See Also:
InstanceVariables.hasInstanceVariable(java.lang.String)

fastHasInstanceVariable

public boolean fastHasInstanceVariable(java.lang.String internedName)
Description copied from interface: InstanceVariables
Returns true if object has the named instance variable. The supplied name must have been previously interned.

Specified by:
fastHasInstanceVariable in interface InstanceVariables
Parameters:
internedName - the interned name of an instance variable
Returns:
true if object has the named instance variable, else false
See Also:
InstanceVariables.fastHasInstanceVariable(java.lang.String)

getInstanceVariable

public IRubyObject getInstanceVariable(java.lang.String name)
Description copied from interface: InstanceVariables
Returns the named instance variable if present, else null.

Specified by:
getInstanceVariable in interface InstanceVariables
Parameters:
name - the name of an instance variable
Returns:
the named instance variable if present, else null
See Also:
InstanceVariables.getInstanceVariable(java.lang.String)

fastGetInstanceVariable

public IRubyObject fastGetInstanceVariable(java.lang.String internedName)
Description copied from interface: InstanceVariables
Returns the named instance variable if present, else null. The supplied name must have been previously interned.

Specified by:
fastGetInstanceVariable in interface InstanceVariables
Parameters:
internedName - the interned name of an instance variable
Returns:
he named instance variable if present, else null
See Also:
InstanceVariables.fastGetInstanceVariable(java.lang.String)

setInstanceVariable

public IRubyObject setInstanceVariable(java.lang.String name,
                                       IRubyObject value)
rb_iv_set / rb_ivar_set

Specified by:
setInstanceVariable in interface InstanceVariables
Parameters:
name - the name of an instance variable
value - the value to be set
See Also:
InstanceVariables.setInstanceVariable(java.lang.String, org.jruby.runtime.builtin.IRubyObject)

fastSetInstanceVariable

public IRubyObject fastSetInstanceVariable(java.lang.String internedName,
                                           IRubyObject value)
Description copied from interface: InstanceVariables
Sets the named instance variable to the specified value. The supplied name must have been previously interned.

Specified by:
fastSetInstanceVariable in interface InstanceVariables
Parameters:
internedName - the interned name of an instance variable
value - the value to be set
See Also:
InstanceVariables.fastSetInstanceVariable(java.lang.String, org.jruby.runtime.builtin.IRubyObject)

removeInstanceVariable

public IRubyObject removeInstanceVariable(java.lang.String name)
Description copied from interface: InstanceVariables
Removes the named instance variable, if present, returning its value.

Specified by:
removeInstanceVariable in interface InstanceVariables
Parameters:
name - the name of the variable to remove
Returns:
the value of the remove variable, if present; else null
See Also:
InstanceVariables.removeInstanceVariable(java.lang.String)

getInstanceVariableList

public java.util.List<Variable<IRubyObject>> getInstanceVariableList()
Specified by:
getInstanceVariableList in interface InstanceVariables
Returns:
instance variables
See Also:
InstanceVariables.getInstanceVariableList()

getInstanceVariableNameList

public java.util.List<java.lang.String> getInstanceVariableNameList()
Specified by:
getInstanceVariableNameList in interface InstanceVariables
Returns:
instance variable names
See Also:
InstanceVariables.getInstanceVariableNameList()

copyInstanceVariablesInto

public void copyInstanceVariablesInto(InstanceVariables other)
Description copied from interface: InstanceVariables
Copies all instance variables from the given object into the receiver

Specified by:
copyInstanceVariablesInto in interface InstanceVariables
See Also:
InstanceVariables.getInstanceVariableNameList()

ensureInstanceVariablesSettable

protected 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.


getNativeTypeIndex

public int getNativeTypeIndex()
Description copied from interface: CoreObjectType
Return 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:
getNativeTypeIndex in interface CoreObjectType
Returns:
the ClassIndex of the native type this object was constructed from


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