Package org.jruby.runtime.ivars
Class VariableAccessor
java.lang.Object
org.jruby.runtime.ivars.VariableAccessor
- Direct Known Subclasses:
FieldVariableAccessor
,StampedVariableAccessor
Abstraction of an accessor for instance or internal variables on Ruby
objects. Subclasses specialize this implementation appropriate to the
current JVM's capabilities and the mechanism for laying out variables.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int
the symbol of the class associated with this variablestatic final VariableAccessor
a dummy accessor that will always return nullprotected final int
the index allocated for it in the variable tableprotected final String
the name of the variableprotected final RubyClass
the "real" class associated with this variable -
Constructor Summary
ConstructorsConstructorDescriptionVariableAccessor
(RubyClass realClass, String name, int index, int classId) Construct a new VariableAccessor for the given "real" class, name, variable index, and class symbol. -
Method Summary
Modifier and TypeMethodDescriptionRetrieve the variable's value from the given object.int
Get the symbol of the class associated with this variable.int
getIndex()
Get the index allocated for this variable.getName()
Get the name of this variable.getOrNil
(Object object, ThreadContext context) Retrieve the variable's value from the given object.getOrUndefined
(Object object) Retrieve object or IR %undefinedstatic Object
getVariable
(RubyBasicObject object, int index) Retrieve the variable's value from the given object.void
Set the value for this variable in the given object.toString()
Produce a string representation of this VariableAccessor.boolean
Verify if this is the correct accessor for the given object.
-
Field Details
-
name
the name of the variable -
index
protected final int indexthe index allocated for it in the variable table -
classId
protected final int classIdthe symbol of the class associated with this variable -
realClass
the "real" class associated with this variable -
DUMMY_ACCESSOR
a dummy accessor that will always return null
-
-
Constructor Details
-
VariableAccessor
Construct a new VariableAccessor for the given "real" class, name, variable index, and class symbol.- Parameters:
realClass
- the "real" classname
- the variable's nameindex
- the variable's indexclassId
- the class's symbol
-
-
Method Details
-
getClassId
public int getClassId()Get the symbol of the class associated with this variable.- Returns:
- this variable's class's id
-
getIndex
public int getIndex()Get the index allocated for this variable.- Returns:
- this variable's index
-
getName
Get the name of this variable.- Returns:
- this variable's name
-
get
Retrieve the variable's value from the given object.- Parameters:
object
- the object from which to retrieve this variable- Returns:
- the variable's value
-
getOrUndefined
Retrieve object or IR %undefined -
getOrNil
Retrieve the variable's value from the given object.- Parameters:
object
- the object from which to retrieve this variable- Returns:
- the variable's value
-
getVariable
Retrieve the variable's value from the given object. This version is static, allowing it to be more direct, and accepts nnly with RubyBasicObject and subclasses along with the direct index of the variable.- Parameters:
object
- the object from which to retrieve the variableindex
- the index of the variable- Returns:
- the variable's value
-
set
Set the value for this variable in the given object.- Parameters:
object
- the object into which to set this variablevalue
- the value of the variable
-
verify
Verify if this is the correct accessor for the given object.- Parameters:
object
- the object for which to test this accessor- Returns:
- true if this is the correct accessor for the given object, false otherwise
-
toString
Produce a string representation of this VariableAccessor.
-