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 class
Class that keeps track of the finalizers for the object under operation. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final ObjectAllocator
Default allocator instance for all Ruby objects.static final int
Deprecated.static final String
The error message used when some one tries to modify an instance variable in a high security setting.static final int
static final int
Deprecated.protected int
object flagsstatic final int
static final int
Deprecated.protected RubyClass
The class of this objectstatic final IRubyObject
A value that is used as a null sentinel in among other places the RubyArray implementation.static final int
This flag is a bit funny.static final int
Deprecated.static final long
Deprecated.static final int
Deprecated.static final IRubyObject
A value that specifies an undefined value.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final int
Deprecated.static final long
Deprecated.Object[]
variable table, lazily allocated as needed (if needed)int
locking stamp for Unsafe ops updating the vartableFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionRubyBasicObject
(RubyClass metaClass) Path for objects that don't enter objectspace.RubyBasicObject
(Ruby runtime, RubyClass metaClass) Standard path for object creation.protected
RubyBasicObject
(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.protected
RubyBasicObject
(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated.addFinalizer
(ThreadContext context, IRubyObject f) Adds 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 and returns it.final IRubyObject
callMethod
(String name) final IRubyObject
callMethod
(String name, IRubyObject arg) final IRubyObject
callMethod
(String name, IRubyObject... args) final IRubyObject
callMethod
(ThreadContext context, int methodIndex, String name) Deprecated.final IRubyObject
callMethod
(ThreadContext context, int methodIndex, String name, IRubyObject arg) Deprecated.final IRubyObject
callMethod
(ThreadContext context, String name) Will invoke a named method with no arguments and no block.final IRubyObject
callMethod
(ThreadContext context, String name, IRubyObject arg) Will invoke a named method with one argument and no block with functional invocation.final IRubyObject
callMethod
(ThreadContext context, String name, IRubyObject[] args) Will invoke a named method with the supplied arguments and no block with functional invocation.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.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 IRubyObject
checkCallMethod
(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 IRubyObject
checkCallMethod
(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.void
The 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".protected RubyBasicObject
cloneSetup
(ThreadContext context, RubyBasicObject clone, IRubyObject freeze) int
compareTo
(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.void
Copies all instance variables from the given object into the receivervoid
Lots of MRI objects keep their state in non-lookupable ivars (e:g.Our version of Data_Get_Struct.Deprecated.void
dataWrapStruct
(Object obj) Our version of Data_Wrap_Struct.raw (id) strings are not properly encoded but in an iso_8859_1 form.display
(ThreadContext context, IRubyObject[] args) dup()
RubyMethod dup.protected void
Stange method.protected RubyBasicObject
dupSetup
(ThreadContext context, RubyBasicObject dup) void
Makes sure that instance variables can be set on this object, including information about whether this object is frozen.boolean
eql
(IRubyObject other) method used for Hash key comparison (specialized for String, Symbol and Fixnum)eql_p
(IRubyObject obj) Deprecated.eql_p
(ThreadContext context, IRubyObject obj) protected static boolean
eqlInternal
(ThreadContext context, IRubyObject that, IRubyObject other) Helper method for checking equality, first using Java identity equality, and then calling the "eql?" method.equal_p
(ThreadContext context, IRubyObject other) rb_obj_equal Will use Java identity equality.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.boolean
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.evalUnder
(ThreadContext context, RubyModule under, RubyString src, String file, int line, EvalType evalType) 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.boolean
fastHasInstanceVariable
(String internedName) Deprecated.boolean
fastHasInternalVariable
(String internedName) Deprecated.fastSetInstanceVariable
(String internedName, IRubyObject value) Deprecated.void
fastSetInternalVariable
(String internedName, Object value) Deprecated.static void
finishBasicObjectClass
(ThreadContext context, RubyClass BasicObject) Will create the Ruby class BasicObject in the runtime specified.void
forEachInstanceVariable
(BiConsumer<String, IRubyObject> accessor) Iterate over all instance variable name/value pairs for this object.void
forEachInstanceVariableName
(Consumer<String> consumer) Iterate over all instance variable names for this object.freeze
(ThreadContext context) frozen_p
(ThreadContext context) final ThreadContext
Deprecated.final Object
final boolean
getFlag
(int flag) Get the value of a custom flag on this object.protected RubyModule
Deprecated.protected RubyModule
getInstanceEvalClass
(ThreadContext context) getInstanceVariable
(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.Class
<?> Will return the Java interface that most closely can represent this object, when working through Java integration translations.all marshable valuesfinal RubyClass
if exist return the meta-class else return the type of the object.static RubyClass
getMetaClass
(IRubyObject arg) Return the ClassIndex for the native type this object was constructed from.final Object
Deprecated.final int
Deprecated.protected long
The logic here is to use the special objectId accessor slot from the parent as a lazy store for an object symbol.final Ruby
Will return the runtime that this object is associated with.Retrieveself.singleton_class
.protected RubyClass
Deprecated.protected RubyClass
Deprecated.protected RubyClass
getSingletonClassCloneAndAttach
(ThreadContext context, RubyBasicObject attach) rb_singleton_class_clone Will make sure that if the current objects class is a singleton, it will get cloned.final RubyClass
getType()
RubyMethod getType.getVariable
(int index) int
Deprecated.Gets a list of all variables in this object.Gets a name list of all variables in this object.hash()
Deprecated.hash
(ThreadContext context) Will return the hash code of this object.int
hashCode()
Override the Object#hashCode method to make sure that the Ruby hash is actually used as the hashcode for Ruby objects.final IRubyObject
boolean
hasInstanceVariable
(String name) Returns true if object has the named instance variable.protected boolean
Check whether this object has any *set* instance variables unrelated to object_id, FFI, and ObjectSpace (which also use hidden ivar slots).boolean
hasInternalVariable
(String name) Returns true if object has the named internal variable.boolean
Returns true if object has any variablesid()
rb_obj_id Return the internal id of an object.infectBy
(IRubyObject obj) Deprecated.initialize
(ThreadContext context) initialize_copy
(IRubyObject original) Deprecated.Useinitialize_copy(ThreadContext, IRubyObject)
instead.initialize_copy
(ThreadContext context, IRubyObject original) Initializes this object as a copy of the original, that is the parameter to this object.inspect()
Deprecated.inspect
(ThreadContext context) Returns a string containing a human-readable representation of obj.protected int
For most objects, the hash used in the default #inspect is just the identity hashcode of the actual object.instance_eval
(ThreadContext context, Block block) instance_eval
(ThreadContext context, IRubyObject[] args, Block block) 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_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_of_p
(ThreadContext context, IRubyObject type) rb_obj_is_instance_of call-seq: obj.instance_of?(class) => true or false Returnstrue
if 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 Returnstrue
if 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.boolean
A method to determine whether the method named by methodName is a builtin method, i.e.boolean
isClass()
Specifically polymorphic method that are meant to be overridden by classes to specify that they are classes in an easy way.final boolean
isFalse()
Is this value a falsey value or not? Based on theFALSE_F
flag.boolean
isFrozen()
Is this value frozen or not? Shortcut for doing getFlag(FROZEN_F).boolean
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.final boolean
isNil()
Does this object represent nil? See the docs for theNIL_F
flag for more information.boolean
Is this a special constantboolean
boolean
isTaint()
Deprecated.final boolean
isTrue()
Is this value a truthy value or not? Based on theFALSE_F
flag.boolean
Deprecated.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 Returnstrue
if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.makeMetaClass
(RubyClass superClass) Deprecated.makeMetaClass
(ThreadContext context, 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.makeMetaClassBootstrap
(Ruby runtime, RubyClass superClass, RubyClass Class) This will create a new metaclass.method
(IRubyObject name) Deprecated.method
(IRubyObject name, StaticScope refinedScope) Deprecated.method
(ThreadContext context, IRubyObject name, StaticScope refinedScope) Likemethod(IRubyObject)
but using the given refinement scope to search for the method.static IRubyObject
method_missing
(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) 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 IRubyObject
methods
(ThreadContext context, IRubyObject[] args, boolean useSymbols) Deprecated.nil_p
(ThreadContext context) rb_false call_seq: nil.nil? => true <anything_else>.nil? => false Only the object nil respondstrue
tonil?
.protected static int
nonFixnumHashCode
(IRubyObject hashValue) Deprecated.protected static int
nonFixnumHashCode
(ThreadContext context, IRubyObject hashValue) protected static boolean
OBJ_INIT_COPY
(IRubyObject obj, IRubyObject orig) protected static void
objInitCopy
(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_match
(ThreadContext context, IRubyObject arg) rb_obj_pattern_match call-seq: obj =~ other => nil Pattern Match---Overridden by descendents (notablyRegexp
andString
) to provide meaningful pattern-match semantics.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) protected_methods
(ThreadContext context, IRubyObject[] args) public_methods
(ThreadContext context, IRubyObject[] args) rbClone()
RubyMethod clone.rbClone
(ThreadContext context, IRubyObject maybeOpts) static IRubyObject
rbInspect
(ThreadContext context, IRubyObject obj) 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.void
Remove 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 RubyBoolean
respond_to_p
(IRubyObject mname) Deprecated.final RubyBoolean
respond_to_p
(IRubyObject mname, IRubyObject includePrivate) Deprecated.final boolean
respondsTo
(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 boolean
respondsToMissing
(String name) Does this object respond to the specified message via "method_missing?"final boolean
respondsToMissing
(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) final void
setFFIHandle
(Object value) final 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.setInstanceVariable
(String name, IRubyObject value) rb_iv_set / rb_ivar_setvoid
setInternalVariable
(String name, Object value) Sets the named internal variable to the specified value.void
setMetaClass
(RubyClass metaClass) Makes it possible to change the metaclass of an object.final void
setNativeHandle
(Object value) Deprecated.void
setTaint
(boolean taint) Deprecated.void
setUntrusted
(boolean untrusted) Deprecated.void
setVariable
(int index, Object value) singleton_method
(IRubyObject name) Deprecated.singleton_method
(ThreadContext context, IRubyObject name) static IRubyObject
singleton_method_added
(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) static IRubyObject
singleton_method_removed
(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) static IRubyObject
singleton_method_undefined
(ThreadContext context, IRubyObject recv, IRubyObject symbolId, Block block) singleton_methods
(ThreadContext context, IRubyObject[] args) singletonClass
(ThreadContext context) Will either return the existing singleton class for this object, or create a new one and return that.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.void
syncVariables
(List<Variable<Object>> variables) Deprecated.void
syncVariables
(IRubyObject other) Sync one this object's variables with other's - this is used to make rbClone work correctly.protected final void
Deprecated.taint
(ThreadContext context) Deprecated.tainted_p
(ThreadContext context) Deprecated.protected final void
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 final void
testFrozen
(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) to_s()
Deprecated.Useto_s(ThreadContext)
instead.to_s
(ThreadContext context) <T> T
Convert 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.untaint
(ThreadContext context) Deprecated.untrust
(ThreadContext context) Deprecated.untrusted_p
(ThreadContext context) Deprecated.protected String
Deprecated.protected String
protected String
validateInstanceVariable
(IRubyObject name, String _unused_) Deprecated.protected boolean
variableTableContains
(String name) Checks if the variable table contains a variable of the specified name.protected boolean
variableTableFastContains
(String internedName) Deprecated.protected Object
variableTableFastFetch
(String internedName) Deprecated.protected Object
variableTableFastStore
(String internedName, Object value) Deprecated.protected Object
variableTableFetch
(String name) Fetch an object from the variable table based on the name.protected Object
variableTableRemove
(String name) Removes the entry with the specified name from the variable table, and returning the removed value.protected Object
variableTableStore
(String name, Object value) Store a value in the variable store under the specific name.protected void
variableTableSync
(List<Variable<Object>> vars) Synchronize the variable table with the argument.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.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.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, dup, marshalLiveVariables
-
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 -
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 -
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:
-
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:
-
TAINTED_F
Deprecated.- See Also:
-
VAR_TABLE_OFFSET
Deprecated.- See Also:
-
STAMP_OFFSET
Deprecated.- See Also:
-
-
Constructor Details
-
RubyBasicObject
Standard path for object creation. Objects are entered into ObjectSpace only if ObjectSpace is enabled.- Parameters:
runtime
- the runtimemetaClass
- the meta class
-
RubyBasicObject
Path for objects that don't enter objectspace.- Parameters:
metaClass
- the new metaclass
-
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)- Parameters:
runtime
- the runtimemetaClass
- the metaclassuseObjectSpace
- should object space be enabled
-
RubyBasicObject
@Deprecated protected RubyBasicObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted) Deprecated.
-
-
Method Details
-
finishBasicObjectClass
Will create the Ruby class BasicObject 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.- Parameters:
context
- the thread contextBasicObject
- reference to BasicObject
-
initialize
-
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.- Parameters:
message
- is frozen
-
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:
checkCallMethod
in 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:
checkCallMethod
in interfaceIRubyObject
-
callMethod
Will invoke a named method with no arguments and no block.- Specified by:
callMethod
in interfaceIRubyObject
-
callMethod
Will invoke a named method with one argument and no block with functional invocation.- Specified by:
callMethod
in interfaceIRubyObject
-
callMethod
Will invoke a named method with the supplied arguments and no block with functional invocation.- Specified by:
callMethod
in 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:
callMethod
in interfaceIRubyObject
-
isNil
public final boolean isNil()Does this object represent nil? See the docs for theNIL_F
flag for more information.- Specified by:
isNil
in interfaceIRubyObject
- Returns:
- true for
nil
only
-
isTrue
public final boolean isTrue()Is this value a truthy value or not? Based on theFALSE_F
flag.- Specified by:
isTrue
in interfaceIRubyObject
- Returns:
- true it truthy
-
isFalse
public final boolean isFalse()Is this value a falsey value or not? Based on theFALSE_F
flag.- Returns:
- true is false
-
isFrozen
public boolean isFrozen()Is this value frozen or not? Shortcut for doing getFlag(FROZEN_F).- Specified by:
isFrozen
in 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:
setFrozen
in interfaceIRubyObject
- Parameters:
frozen
- should this object be frozen?
-
isImmediate
public boolean isImmediate()Is object immediate (def: Fixnum, Symbol, true, false, nil?).- Specified by:
isImmediate
in interfaceIRubyObject
- Returns:
- boolean
-
isSpecialConst
public boolean isSpecialConst()Description copied from interface:IRubyObject
Is this a special constant- Specified by:
isSpecialConst
in interfaceIRubyObject
- Returns:
- boolean
-
isSpecialObject
public boolean isSpecialObject() -
getMetaClass
if exist return the meta-class else return the type of the object.- Specified by:
getMetaClass
in interfaceIRubyObject
- Returns:
- the Ruby (meta) class
-
getMetaClass
-
getSingletonClass
Description copied from interface:IRubyObject
Retrieveself.singleton_class
.- Specified by:
getSingletonClass
in interfaceIRubyObject
- Returns:
- the Ruby singleton class
-
singletonClass
Will either return the existing singleton class for this object, or create a new one and return that. For a few types a singleton class is not possible so it will throw an error.- Specified by:
singletonClass
in interfaceIRubyObject
- Parameters:
context
- the current thread context- Returns:
- the singleton of this type
-
makeMetaClass
Deprecated. -
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.- Parameters:
context
- the thread contextsuperClass
- the super class- Returns:
- the new meta class
-
makeMetaClassBootstrap
This will create a new metaclass. This is only used during bootstrapping before the initial ThreadContext is defined. Normal needs of making a metaclass should usemakeMetaClass(ThreadContext, RubyClass)
- Parameters:
runtime
- the runtimesuperClass
- of the metaclassClass
- a reference to Ruby Class- Returns:
- the new metaclass
-
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.- Parameters:
metaClass
- the meta class to set
-
getType
Description copied from interface:IRubyObject
RubyMethod getType.- Specified by:
getType
in 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:
respondsTo
in interfaceIRubyObject
- Parameters:
name
- method name- Returns:
- boolean
-
respondsToMissing
Does this object respond to the specified message via "method_missing?"- Specified by:
respondsToMissing
in interfaceIRubyObject
- Parameters:
name
- method name- Returns:
- boolean
-
respondsToMissing
Does this object respond to the specified message via "method_missing?"- Specified by:
respondsToMissing
in interfaceIRubyObject
- Parameters:
name
- method nameincPrivate
- private?- Returns:
- boolean
-
getRuntime
Will return the runtime that this object is associated with.- Specified by:
getRuntime
in interfaceIRubyObject
- Returns:
- current runtime
-
getCurrentContext
Deprecated. -
getJavaClass
Will return the Java interface that most closely can represent this object, when working through Java integration translations.- Specified by:
getJavaClass
in 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:
asJavaString
in interfaceIRubyObject
- Returns:
- a (Java) string
-
asString
rb_obj_as_string First converts this object into a String using the "to_s" method and returns it. If to_s doesn't return a Ruby String,anyToString()
is used instead.- Specified by:
asString
in interfaceIRubyObject
- Returns:
- string representation
-
convertToArray
Tries to convert this object to a Ruby Array using the "to_ary" method.- Specified by:
convertToArray
in interfaceIRubyObject
- Returns:
- array representation of this
-
convertToHash
Tries to convert this object to a Ruby Hash using the "to_hash" method.- Specified by:
convertToHash
in interfaceIRubyObject
- Returns:
- hash representation of this
-
convertToFloat
Tries to convert this object to a Ruby Float using the "to_f" method.- Specified by:
convertToFloat
in interfaceIRubyObject
- Returns:
- float representation of this
-
convertToInteger
Tries to convert this object to a Ruby Integer using the "to_int" method.- Specified by:
convertToInteger
in interfaceIRubyObject
- Returns:
- an integer representation of this
-
convertToInteger
Tries to convert this object to a Ruby Integer using the supplied conversion method.- Specified by:
convertToInteger
in 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:
convertToString
in 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:
anyToString
in interfaceIRubyObject
- Returns:
- a string value
-
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.- Parameters:
id
- the id of the string- Returns:
- the string of the symbol found from id
-
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 interfaceIRubyObject
- Returns:
- nil if type check failed
-
checkArrayType
rb_check_array_type Returns the result of trying to convert this object to an Array with "to_ary".- Specified by:
checkArrayType
in interfaceIRubyObject
- Returns:
- nil if type check failed
-
toJava
Description copied from interface:IRubyObject
Convert the object to the specified Java class, if possible.- Specified by:
toJava
in interfaceIRubyObject
- Type Parameters:
T
- type- Parameters:
target
- The target type to which the object should be converted.- Returns:
- java type
- See Also:
-
dup
Description copied from interface:IRubyObject
RubyMethod dup.- Specified by:
dup
in interfaceIRubyObject
- Returns:
- a dup-ed object
-
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:
copySpecialInstanceVariables
in interfaceIRubyObject
-
rbClone
Description copied from interface:IRubyObject
RubyMethod clone.- Specified by:
rbClone
in interfaceIRubyObject
- Returns:
- a cloned object
-
rbClone
-
dupSetup
-
cloneSetup
protected RubyBasicObject cloneSetup(ThreadContext context, RubyBasicObject clone, IRubyObject freeze) -
getSingletonClassClone
Deprecated. -
getSingletonClassCloneAndAttach
@Deprecated(since="10.0") protected RubyClass getSingletonClassCloneAndAttach(RubyBasicObject attach) Deprecated. -
getSingletonClassCloneAndAttach
rb_singleton_class_clone Will make sure that if the current objects class is a singleton, it will get cloned.- Parameters:
context
- the thread contextattach
- object ot attach- 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 interfaceIRubyObject
- Returns:
- true if an object is Ruby Module instance (note that it will return false for Ruby Classes).
-
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 interfaceIRubyObject
- Returns:
- true if an object is Ruby Class instance (note that it will return false for Ruby singleton classes).
-
dataWrapStruct
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 interfaceIRubyObject
- Parameters:
obj
- the object to wrap- See Also:
-
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 interfaceIRubyObject
- Returns:
- the object wrapped.
- See Also:
-
id
rb_obj_id Return the internal id of an object.- Specified by:
id
in 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.- Returns:
- object id
-
inspect
Deprecated.Description copied from interface:IRubyObject
RubyMethod inspect.- Specified by:
inspect
in interfaceIRubyObject
- Returns:
- String
-
inspect
Returns a string containing a human-readable representation of obj. If not overridden, uses theto_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 interfaceIRubyObject
-
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
-
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:
compareTo
in 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_equal
in interfaceIRubyObject
-
op_eqq
- Specified by:
op_eqq
in interfaceIRubyObject
-
equalInternal
Helper method for checking equality, first using Java identity equality, and then calling the "==" method.- Parameters:
context
- the thread contextthat
- first comparatorother
- the second comparator- Returns:
- are they equal
-
eqlInternal
Helper method for checking equality, first using Java identity equality, and then calling the "eql?" method.- Parameters:
context
- the thread contextthat
- first comparatorother
- the second comparator- Returns:
- are they equal
-
eql
method used for Hash key comparison (specialized for String, Symbol and Fixnum)- Specified by:
eql
in interfaceIRubyObject
- Returns:
- Will by default just call the Ruby method "eql?"
-
addFinalizer
Deprecated.- Specified by:
addFinalizer
in interfaceIRubyObject
-
addFinalizer
Adds the specified object as a finalizer for this object.- Specified by:
addFinalizer
in interfaceIRubyObject
-
dupFinalizer
protected void dupFinalizer()Stange method. We will dup the __finalizer__ variable in a freshly dup'd object, but it needs to be set to this objects __finalizer__. -
removeFinalizers
public void removeFinalizers()Remove all the finalizers for this object.- Specified by:
removeFinalizers
in interfaceIRubyObject
-
getVariable
- Specified by:
getVariable
in interfaceIRubyObject
-
setVariable
- Specified by:
setVariable
in interfaceIRubyObject
-
getFFIHandle
-
setFFIHandle
-
hasVariables
public boolean hasVariables()Returns true if object has any variables- Specified by:
hasVariables
in 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:
getVariableList
in interfaceIRubyObject
- Returns:
- a list of all variables (ivar/internal)
-
getMarshalVariableList
Description copied from interface:IRubyObject
all marshable values- Specified by:
getMarshalVariableList
in interfaceIRubyObject
- Returns:
- a mutable list of all marshalable variables (ivar/internal)
- See Also:
-
getVariableNameList
Gets a name list of all variables in this object.- Specified by:
getVariableNameList
in 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.- Parameters:
name
- to lookup- Returns:
- if contained in this object
-
variableTableFetch
Fetch an object from the variable table based on the name.- Parameters:
name
- to lookup- Returns:
- the object or null if not found
-
variableTableStore
Store a value in the variable store under the specific name.- Parameters:
name
- to store invalue
- to store- Returns:
- value
-
variableTableRemove
Removes the entry with the specified name from the variable table, and returning the removed value.- Parameters:
name
- to remove- Returns:
- the value removed
-
variableTableSync
Synchronize the variable table with the argument. In real terms this means copy all entries into a newly allocated table.- Parameters:
vars
- to to sync with
-
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 interfaceIRubyObject
-
hasInternalVariable
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 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:InternalVariables
Returns the named internal variable if present, else null. Use only for internal variables (not ivar/cvar/constant).- Specified by:
getInternalVariable
in 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:InternalVariables
Sets the named internal variable to the specified value. Use only for internal variables (not ivar/cvar/constant).- Specified by:
setInternalVariable
in interfaceInternalVariables
- Parameters:
name
- the name of an internal variablevalue
- the value to be set- See Also:
-
removeInternalVariable
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 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:
syncVariables
in 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:
getInstanceVariables
in interfaceIRubyObject
-
hasInstanceVariable
Description copied from interface:InstanceVariables
Returns true if object has the named instance variable.- Specified by:
hasInstanceVariable
in 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:InstanceVariables
Returns the named instance variable if present, else null.- Specified by:
getInstanceVariable
in 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:
setInstanceVariable
in interfaceInstanceVariables
- Parameters:
name
- the name of an instance variablevalue
- the value to be set- Returns:
- value
- See Also:
-
removeInstanceVariable
Description copied from interface:InstanceVariables
Removes the named instance variable, if present, returning its value.- Specified by:
removeInstanceVariable
in 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:
getInstanceVariableList
in interfaceInstanceVariables
- Returns:
- instance variables
-
getInstanceVariableNameList
Gets a name list of all variables in this object.- Specified by:
getInstanceVariableNameList
in interfaceInstanceVariables
- Returns:
- instance variable names
-
forEachInstanceVariableName
Description copied from interface:InstanceVariables
Iterate over all instance variable names for this object.- Specified by:
forEachInstanceVariableName
in interfaceInstanceVariables
- Parameters:
consumer
- consumer for the names
-
copyInstanceVariablesInto
Description copied from interface:InstanceVariables
Copies all instance variables from the given object into the receiver- Specified by:
copyInstanceVariablesInto
in interfaceInstanceVariables
- Parameters:
other
- the thing to copy into
-
ensureInstanceVariablesSettable
public void ensureInstanceVariablesSettable()Makes sure that instance variables can be set on this object, including information about whether this object is frozen. Will throw a suitable exception in that case. -
forEachInstanceVariable
Description copied from interface:InstanceVariables
Iterate over all instance variable name/value pairs for this object.- Specified by:
forEachInstanceVariable
in interfaceInstanceVariables
- Parameters:
accessor
- a consumer for each variable
-
getNativeTypeIndex
Deprecated.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 interfaceCoreObjectType
- Returns:
- the ClassIndex of the native type this object was constructed from
-
getNativeClassIndex
Description copied from interface:CoreObjectType
Return the ClassIndex for the native type this object was constructed from.- Specified by:
getNativeClassIndex
in interfaceCoreObjectType
- Returns:
- the ClassIndex of the native type this object was constructed from
-
isBuiltin
A method to determine whether the method named by methodName is a builtin method, i.e. a method built-in to JRuby and loaded during its core boot process.- 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) -
method_missing
public static IRubyObject method_missing(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) -
send
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.- Parameters:
context
- the thread contextunder
- module to yield inargs
- to useblock
- to callevalType
- type of evaal to perform- Returns:
- the result
-
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.- Parameters:
context
- the thread contextunder
- module to yield inblock
- to callevalType
- type of evaal to perform- Returns:
- the result
-
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.- Parameters:
context
- the thread contextmod
- module to yield inblock
- to callevalType
- type of evaal to perform- Returns:
- the result
-
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.- Parameters:
context
- the thread contextmod
- module to yield inarg
- to pass to blockblock
- to callevalType
- type of evaal to perform- Returns:
- the result
-
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.- Parameters:
context
- the thread contextmod
- module to yield inarg0
- to pass to blockarg1
- to pass to blockblock
- to callevalType
- type of evaal to perform- Returns:
- the result
-
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.- Parameters:
context
- the thread contextmod
- module to yield inarg0
- to pass to blockarg1
- to pass to blockarg2
- to pass to blockblock
- to callevalType
- type of evaal to perform- Returns:
- the result
-
getInstanceEvalClass
Deprecated. -
getInstanceEvalClass
-
evalUnder
public IRubyObject evalUnder(ThreadContext context, RubyModule under, RubyString src, String file, int line, EvalType evalType) -
equal_p
rb_obj_equal Will use Java identity equality.- Parameters:
context
- the thread contextother
- to compare with- Returns:
- are they equal?
-
eql_p
Deprecated. -
eql_p
-
op_cmp
-
initialize_copy
Deprecated.Useinitialize_copy(ThreadContext, IRubyObject)
instead.- Parameters:
original
- object- Returns:
- a copy
-
initialize_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.- Parameters:
context
- the thread contextoriginal
- the original- Returns:
- a copy unless the same thing
-
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. -
respond_to_p
Deprecated. -
hash
Deprecated.Usehash(ThreadContext)
instead.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.- Returns:
- hash value
-
hash
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.- Parameters:
context
- the current thread context- Returns:
- the hash value
-
type
rb_obj_class Returns the real class of this object, excluding any singleton/meta class in the inheritance chain.- Returns:
- the real class
-
display
-
freeze
-
frozen_p
-
instance_of_p
rb_obj_is_instance_of call-seq: obj.instance_of?(class) => true or false Returnstrue
if obj is an instance of the given class. See alsoObject#kind_of?
.- Parameters:
context
- the thread contexttype
- the type- Returns:
- true if this is instance of type
-
kind_of_p
rb_obj_is_kind_of call-seq: obj.is_a?(class) => true or false obj.kind_of?(class) => true or false Returnstrue
if 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- Parameters:
context
- the thread contexttype
- the type- Returns:
- true if this is kind of type
-
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- Parameters:
context
- the thread contextargs
- include ancestors- Returns:
- methods
-
methods
@Deprecated public final IRubyObject methods(ThreadContext context, IRubyObject[] args, boolean useSymbols) Deprecated. -
public_methods
-
protected_methods
-
private_methods
-
singleton_methods
-
singleton_method
Deprecated. -
singleton_method
-
method
Deprecated. -
method
Deprecated. -
method
Likemethod(IRubyObject)
but using the given refinement scope to search for the method.- Parameters:
context
- the thread contextname
- the name of the methodrefinedScope
- the static scope for the caller method- Returns:
- method instance
-
to_s
Deprecated.Useto_s(ThreadContext)
instead.- Returns:
- ""
-
to_s
-
to_a
-
instance_eval
-
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_eval
-
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 @secret = 99 end end k = Klass.new k.instance_exec(5) {|x| @secret+x } #=> 104- Parameters:
context
- the thread contextargs
- the argsblock
- block- Returns:
- the result
-
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"- Parameters:
args
- to use as modules to extend- Returns:
- itself
-
nil_p
rb_false call_seq: nil.nil? => true <anything_else>.nil? => false Only the object nil respondstrue
tonil?
.- Parameters:
context
- the thread context- Returns:
- true if nil
-
op_match
rb_obj_pattern_match call-seq: obj =~ other => nil Pattern Match---Overridden by descendents (notablyRegexp
andString
) to provide meaningful pattern-match semantics.- Parameters:
context
- the thread contextarg
- arg- Returns:
- true if matches (always nil)
-
op_not_match
Invert the match operator.- Parameters:
context
- the thread contextarg
- arg- Returns:
- true if they do not match
-
instance_variable_defined_p
rb_obj_ivar_defined call-seq: obj.instance_variable_defined?(symbol) => true or false Returnstrue
if the given instance variable is defined in obj. class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_defined?(:@a) #=> true fred.instance_variable_defined?("@b") #=> true fred.instance_variable_defined?("@c") #=> false- Parameters:
context
- the thread contextname
- of ivar- Returns:
- true if defined
-
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 aNameError
exception if the supplied symbol is not valid as an instance variable name. class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_get(:@a) #=> "cat" fred.instance_variable_get("@b") #=> 99- Parameters:
context
- the thread contextname
- of ivar- Returns:
- value of ivar
-
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) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_set(:@a, 'dog') #=> "dog" fred.instance_variable_set(:@c, 'cat') #=> "cat" fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"- Parameters:
name
- of ivarvalue
- to set- Returns:
- value of old set ivar
-
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 @var = 99 end def remove remove_instance_variable(:@var) end end d = Dummy.new d.var #=> 99 d.remove #=> 99 d.var #=> nil- Parameters:
context
- the thread contextname
- of ivarblock
- the block (not used)- Returns:
- value of removed ivar
-
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 @iv = 3 end end Fred.new.instance_variables #=> [:"@iv"]- Parameters:
context
- the thread context- Returns:
- list of ivars
-
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
Deprecated. -
nonFixnumHashCode
-
validateInstanceVariable
Deprecated.Checks if the name parameter represents a legal instance variable name, and otherwise throws a Ruby NameError- Parameters:
name
- of instance variable- Returns:
- name it is valid
-
validateInstanceVariable
Deprecated. -
validateInstanceVariable
-
callSuper
Deprecated.- Specified by:
callSuper
in interfaceIRubyObject
-
callMethod
@Deprecated public final IRubyObject callMethod(ThreadContext context, int methodIndex, String name) Deprecated.- Specified by:
callMethod
in interfaceIRubyObject
-
callMethod
@Deprecated public final IRubyObject callMethod(ThreadContext context, int methodIndex, String name, IRubyObject arg) Deprecated.- Specified by:
callMethod
in interfaceIRubyObject
-
convertToInteger
Deprecated.Description copied from interface:IRubyObject
convert this object to an integer- Specified by:
convertToInteger
in interfaceIRubyObject
- Parameters:
methodIndex
- indexconvertMethod
- conversion method name- Returns:
- integer
- See Also:
-
getVariableCount
Deprecated.Description copied from interface:IRubyObject
how many variables?- Specified by:
getVariableCount
in interfaceIRubyObject
- Returns:
- the count of all variables (ivar/cvar/constant/internal)
-
variableTableFastContains
Deprecated. -
variableTableFastFetch
Deprecated. -
variableTableFastStore
Deprecated. -
fastHasInternalVariable
Deprecated.- Specified by:
fastHasInternalVariable
in interfaceInternalVariables
-
fastGetInternalVariable
Deprecated.- Specified by:
fastGetInternalVariable
in interfaceInternalVariables
-
fastSetInternalVariable
Deprecated.- Specified by:
fastSetInternalVariable
in interfaceInternalVariables
-
syncVariables
Deprecated.Description copied from interface:IRubyObject
Sets 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:
syncVariables
in interfaceIRubyObject
- Parameters:
variables
- the variables to be set for object
-
fastHasInstanceVariable
Deprecated.- Specified by:
fastHasInstanceVariable
in interfaceInstanceVariables
-
fastGetInstanceVariable
Deprecated.- Specified by:
fastGetInstanceVariable
in interfaceInstanceVariables
-
fastSetInstanceVariable
Deprecated.- Specified by:
fastSetInstanceVariable
in interfaceInstanceVariables
-
isUntrusted
Deprecated.Description copied from interface:IRubyObject
RubyMethod isUntrusted.- Specified by:
isUntrusted
in interfaceIRubyObject
- Returns:
- boolean
-
setUntrusted
Deprecated.Description copied from interface:IRubyObject
RubyMethod setUntrusted.- Specified by:
setUntrusted
in interfaceIRubyObject
- Parameters:
untrusted
- boolean
-
untrusted_p
Deprecated. -
untrust
Deprecated. -
trust
Deprecated. -
getNativeHandle
Deprecated. -
setNativeHandle
Deprecated. -
dataGetStructChecked
Deprecated.- Specified by:
dataGetStructChecked
in interfaceIRubyObject
-
to_a
Deprecated. -
tainted_p
Deprecated. -
taint
Deprecated. -
taint
Deprecated. -
untaint
Deprecated. -
isTaint
Deprecated.- Specified by:
isTaint
in interfaceIRubyObject
-
setTaint
Deprecated.- Specified by:
setTaint
in interfaceIRubyObject
-
infectBy
Deprecated.- Specified by:
infectBy
in interfaceIRubyObject
-
hash(ThreadContext)
instead.