org.jruby
Class RubyObject

java.lang.Object
  extended by org.jruby.RubyBasicObject
      extended by org.jruby.RubyObject
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<IRubyObject>, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType
Direct Known Subclasses:
AbstractInvoker, AbstractMemory, DynamicLibrary, DynamicLibrary, FiberLibrary.Fiber, JavaAccessibleObject, JavaObject, JavaProxy, JavaProxyReflectionObject, JNAVariadicInvoker, JRubyObjectInputStream, MiniJava.JavaObjectWrapper, MockRubyObject, RubyArray, RubyBinding, RubyBoolean, RubyClassPathVariable, RubyContinuation, RubyConverter, RubyDigest.Base, RubyDir, RubyEncoding, RubyEnumerator, RubyException, RubyFileStat, RubyGenerator, RubyHash, RubyIconv, RubyIO, RubyMatchData, RubyMethod, RubyModule, RubyNameError.RubyNameErrorMessage, RubyNil, RubyNumeric, RubyProc, RubyProcess.RubyStatus, RubyRange, RubyRegexp, RubyString, RubyStringIO, RubyStringScanner, RubyStruct, RubySymbol, RubyThread, RubyThreadGroup, RubyTime, RubyYielder, RubyZlib.RubyGzipFile, RubyZlib.ZStream, Struct, StructLayout.Array, StructLayoutBuilder, TestRubyClass.MyRubyObjectSubclass, ThreadLibrary.ConditionVariable, ThreadLibrary.Mutex, ThreadLibrary.Queue, Type, VariadicInvoker, WeakRef

public class RubyObject
extends RubyBasicObject

RubyObject is the only implementation of the IRubyObject. Every Ruby object in JRuby is represented by something that is an instance of RubyObject. In some of the core class implementations, this means doing a subclass that extends RubyObject, in other cases it means using a simple RubyObject instance and the data field 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 RubyBasicObject.getInstanceVariables() and RubyBasicObject.getInternalVariables().

Author:
jpetersen
See Also:
Serialized Form

Nested Class Summary
static class RubyObject.ObjectMethods
          Interestingly, the Object class doesn't really have that many methods for itself.
 
Nested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.BasicObjectMethods, RubyBasicObject.Finalizer
 
Field Summary
static ObjectAllocator OBJECT_ALLOCATOR
          Default allocator instance for all Ruby objects.
 
Fields inherited from class org.jruby.RubyBasicObject
ALL_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, TAINTED_F, UNDEF, UNTRUSTED_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
  RubyObject(RubyClass metaClass)
          Path for objects that don't taint and don't enter objectspace.
  RubyObject(Ruby runtime, RubyClass metaClass)
          Standard path for object creation.
protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace)
           
protected RubyObject(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
 IRubyObject as(java.lang.Class javaClass)
           
 void attachToObjectSpace()
          Will make sure that this object is added to the current object space.
 void callInit(IRubyObject[] args, Block block)
          Call the Ruby initialize method with the supplied arguments and block.
protected  void checkFrozen()
          The actual method that checks frozen with the default frozen message from MRI.
 IRubyObject convertToType(RubyClass target, int convertMethodIndex)
          Deprecated. 
static RubyClass createObjectClass(Ruby runtime, RubyClass objectClass)
          Will create the Ruby class Object in the runtime specified.
 IRubyObject display(ThreadContext context, IRubyObject[] args)
          rb_obj_display call-seq: obj.display(port=$>) => nil Prints obj on the given port (default $>).
 IRubyObject dup()
          rb_obj_dup This method should be overridden only by: Proc Will allocate a new instance of the real class of this object, and then initialize that copy.
 IRubyObject eql_p(IRubyObject obj)
          rb_obj_equal Just like "==" and "equal?", "eql?" will use identity equality for Object.
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.
 IRubyObject equal_p(ThreadContext context, IRubyObject obj)
          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 equals(java.lang.Object other)
          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.
 IRubyObject evalUnder(ThreadContext context, RubyModule under, IRubyObject src, IRubyObject file, IRubyObject line)
          Deprecated. Call with an int line number and String file
 IRubyObject evalUnder(ThreadContext context, RubyModule under, RubyString src, java.lang.String file, int line)
          Evaluates the string src with self set to the current object, using the module under as the context.
 IRubyObject 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.
 IRubyObject freeze(ThreadContext context)
          rb_obj_freeze call-seq: obj.freeze => obj Prevents further modifications to obj.
 RubyBoolean frozen_p(ThreadContext context)
          rb_obj_frozen_p call-seq: obj.frozen? => true or false Returns the freeze status of obj.
 int getNativeTypeIndex()
          This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.
 RubyFixnum hash()
          rb_obj_id 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.
 IRubyObject id_deprecated()
          rb_obj_id_obsolete Old id version.
 IRubyObject id()
          rb_obj_id Return the internal id of an object.
 IRubyObject initialize_copy(IRubyObject original)
          rb_obj_init_copy Initializes this object as a copy of the original, that is the parameter to this object.
 IRubyObject initialize()
          rb_obj_dummy Default initialize method.
 IRubyObject inspect()
          rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj.
 IRubyObject instance_eval(ThreadContext context, Block block)
          rb_obj_instance_eval call-seq: obj.instance_eval(string [, filename [, lineno]] ) => obj obj.instance_eval {| | block } => obj Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (_obj_).
 IRubyObject instance_eval(ThreadContext context, IRubyObject[] args, Block block)
          Deprecated. 
 IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, Block block)
           
 IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block)
           
 IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
           
 IRubyObject 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_).
 RubyBoolean instance_of_p(ThreadContext context, IRubyObject type)
          rb_obj_is_instance_of call-seq: obj.instance_of?(class) => true or false Returns true if obj is an instance of the given class.
 IRubyObject instance_variable_defined_p(ThreadContext context, IRubyObject name)
          rb_obj_ivar_defined call-seq: obj.instance_variable_defined?(symbol) => true or false Returns true if the given instance variable is defined in obj.
 IRubyObject 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.
 IRubyObject 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.
 RubyArray instance_variables(ThreadContext context)
          rb_obj_instance_variables call-seq: obj.instance_variables => array Returns an array of instance variable names for the receiver.
 RubyBoolean 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 Returns true if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.
 IRubyObject method(IRubyObject symbol)
          rb_obj_method call-seq: obj.method(sym) => method Looks up the named method as a receiver in obj, returning a Method object (or raising NameError).
 IRubyObject 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.
 IRubyObject nil_p(ThreadContext context)
          rb_false call_seq: nil.nil? => true .nil? => false Only the object nil responds true to nil?.
 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_match(ThreadContext context, IRubyObject arg)
          rb_obj_pattern_match call-seq: obj =~ other => false Pattern Match---Overridden by descendents (notably Regexp and String) to provide meaningful pattern-match semantics.
 IRubyObject private_methods(ThreadContext context, IRubyObject[] args)
          rb_obj_private_methods call-seq: obj.private_methods(all=true) => array Returns the list of private methods accessible to obj.
 IRubyObject protected_methods(ThreadContext context, IRubyObject[] args)
          rb_obj_protected_methods call-seq: obj.protected_methods(all=true) => array Returns the list of protected methods accessible to obj.
 IRubyObject public_methods(ThreadContext context, IRubyObject[] args)
          rb_obj_public_methods call-seq: obj.public_methods(all=true) => array Returns the list of public methods accessible to obj.
static void puts(java.lang.Object obj)
          Simple helper to print any objects.
 IRubyObject rbClone()
          rb_obj_clone This method should be overridden only by: Proc, Method, UnboundedMethod, Binding.
 IRubyObject 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.
 RubyBoolean respond_to_p(IRubyObject mname)
          obj_respond_to respond_to?( aSymbol, includePriv=false ) -> true or false Returns true if this object responds to the given method.
 RubyBoolean respond_to_p(IRubyObject mname, IRubyObject includePrivate)
          obj_respond_to respond_to?( aSymbol, includePriv=false ) -> true or false Returns true if this object responds to the given method.
 IRubyObject send(ThreadContext context, Block block)
          rb_f_send send( aSymbol [, args ]* ) -> anObject Invokes the method identified by aSymbol, passing it any arguments specified.
 IRubyObject send(ThreadContext context, IRubyObject[] args, Block block)
           
 IRubyObject send(ThreadContext context, IRubyObject arg0, Block block)
           
 IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block)
           
 IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
           
 RubyArray singleton_methods(ThreadContext context, IRubyObject[] args)
          rb_obj_singleton_methods call-seq: obj.singleton_methods(all=true) => array Returns an array of the names of singleton methods for obj.
 RubyArray singleton_methods19(ThreadContext context, IRubyObject[] args)
           
 RubyArray singletonMethods(ThreadContext context, IRubyObject[] args, boolean asSymbols)
           
 IRubyObject specificEval(ThreadContext context, RubyModule mod, Block block)
          specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.
 IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject[] args, Block block)
          Deprecated. 
 IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg, Block block)
          specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.
 IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, Block block)
          specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.
 IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
          specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments.
 IRubyObject taint(ThreadContext context)
          rb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the $SAFE level is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.
 RubyBoolean tainted_p(ThreadContext context)
          rb_obj_tainted call-seq: obj.tainted? => true or false Returns true if the object is tainted.
 RubyArray to_a()
          rb_any_to_a call-seq: obj.to_a -> anArray Returns an array representation of obj.
 IRubyObject to_java()
           
 IRubyObject to_s()
          rb_any_to_s call-seq: obj.to_s => string Returns a string representing obj.
 java.lang.String toString()
          The default toString method is just a wrapper that calls the Ruby "to_s" method.
 IRubyObject trust(ThreadContext context)
          rb_obj_trust call-seq: obj.trust => obj Removes the untrusted mark from obj.
 RubyClass type_deprecated()
          rb_obj_type The deprecated version of type, that emits a deprecation warning.
 RubyClass type()
          rb_obj_class Returns the real class of this object, excluding any singleton/meta class in the inheritance chain.
 IRubyObject untaint(ThreadContext context)
          rb_obj_untaint call-seq: obj.untaint => obj Removes the taint from obj.
 IRubyObject untrust(ThreadContext context)
          rb_obj_untrust call-seq: obj.untrust -> obj Marks obj as untrusted.
 RubyBoolean untrusted_p(ThreadContext context)
          rb_obj_untrusted call-seq: obj.untrusted? => true or false Returns true if the object is untrusted.
protected  java.lang.String validateInstanceVariable(java.lang.String name)
          Checks if the name parameter represents a legal instance variable name, and otherwise throws a Ruby NameError
 
Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkStringType, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataWrapStruct, ensureInstanceVariablesSettable, eql, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, getFlag, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hasInstanceVariable, hasInternalVariable, hasVariables, infectBy, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isTaint, isTrue, isUntrusted, makeMetaClass, op_not_equal, op_not, removeFinalizers, removeInstanceVariable, removeInternalVariable, respondsTo, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, setUntrusted, setVariable, syncVariables, taint, testFrozen, testFrozen, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableGetSize, variableTableRemove, variableTableStore, variableTableSync
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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
Constructor Detail

RubyObject

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


RubyObject

public RubyObject(RubyClass metaClass)
Path for objects that don't taint and don't enter objectspace.


RubyObject

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


RubyObject

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

createObjectClass

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


attachToObjectSpace

public void attachToObjectSpace()
Will make sure that this object is added to the current object space.

See Also:
ObjectSpace

getNativeTypeIndex

public int getNativeTypeIndex()
This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are. Will generally return a value from org.jruby.runtime.ClassIndex

Specified by:
getNativeTypeIndex in interface CoreObjectType
Overrides:
getNativeTypeIndex in class RubyBasicObject
Returns:
the ClassIndex of the native type this object was constructed from
See Also:
org.jruby.runtime.ClassInde

puts

public static void puts(java.lang.Object obj)
Simple helper to print any objects.


equals

public boolean equals(java.lang.Object other)
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.

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
The default toString method is just a wrapper that calls the Ruby "to_s" method.

Overrides:
toString in class java.lang.Object

checkFrozen

protected void checkFrozen()
The actual method that checks frozen with the default frozen message from MRI. If possible, call this instead of RubyBasicObject.testFrozen(java.lang.String).


callInit

public final void callInit(IRubyObject[] args,
                           Block block)
Call the Ruby initialize method with the supplied arguments and block.


convertToType

@Deprecated
public final IRubyObject convertToType(RubyClass target,
                                                  int convertMethodIndex)
Deprecated. 

Tries to convert this object to the specified Ruby type, using a specific conversion method.


specificEval

@Deprecated
public IRubyObject specificEval(ThreadContext context,
                                           RubyModule mod,
                                           IRubyObject[] args,
                                           Block block)
Deprecated. 

specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments. If a block is given, this will be yielded in the specific context of this object. If no block is given then a String-like object needs to be the first argument, and this string will be evaluated. Second and third arguments in the args-array is optional, but can contain the filename and line of the string under evaluation.


specificEval

public IRubyObject specificEval(ThreadContext context,
                                RubyModule mod,
                                Block block)
specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments. If a block is given, this will be yielded in the specific context of this object. If no block is given then a String-like object needs to be the first argument, and this string will be evaluated. Second and third arguments in the args-array is optional, but can contain the filename and line of the string under evaluation.


specificEval

public IRubyObject specificEval(ThreadContext context,
                                RubyModule mod,
                                IRubyObject arg,
                                Block block)
specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments. If a block is given, this will be yielded in the specific context of this object. If no block is given then a String-like object needs to be the first argument, and this string will be evaluated. Second and third arguments in the args-array is optional, but can contain the filename and line of the string under evaluation.


specificEval

public IRubyObject specificEval(ThreadContext context,
                                RubyModule mod,
                                IRubyObject arg0,
                                IRubyObject arg1,
                                Block block)
specific_eval Evaluates the block or string inside of the context of this object, using the supplied arguments. If a block is given, this will be yielded in the specific context of this object. If no block is given then a String-like object needs to be the first argument, and this string will be evaluated. Second and third arguments in the args-array is optional, but can contain the filename and line of the string under evaluation.


specificEval

public IRubyObject specificEval(ThreadContext context,
                                RubyModule mod,
                                IRubyObject arg0,
                                IRubyObject arg1,
                                IRubyObject arg2,
                                Block block)
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.


evalUnder

public IRubyObject evalUnder(ThreadContext context,
                             RubyModule under,
                             IRubyObject src,
                             IRubyObject file,
                             IRubyObject line)
Deprecated. Call with an int line number and String file

Evaluates the string src with self set to the current object, using the module under as the context.


evalUnder

public IRubyObject evalUnder(ThreadContext context,
                             RubyModule under,
                             RubyString src,
                             java.lang.String file,
                             int line)
Evaluates the string src with self set to the current object, using the module under as the context.


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
Overrides:
op_equal in class RubyBasicObject

equal_p

public IRubyObject equal_p(ThreadContext context,
                           IRubyObject obj)
rb_obj_equal Will use Java identity equality.


eql_p

public IRubyObject eql_p(IRubyObject obj)
rb_obj_equal Just like "==" and "equal?", "eql?" will use identity equality for Object.


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
Overrides:
op_eqq in class RubyBasicObject

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.


eqlInternal

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.


initialize_copy

public IRubyObject initialize_copy(IRubyObject original)
rb_obj_init_copy Initializes this object as a copy of the original, that is the parameter to this object. Will make sure that the argument actually has the same real class as this object. It shouldn't be possible to initialize an object with something totally different.


respond_to_p

public RubyBoolean respond_to_p(IRubyObject mname)
obj_respond_to respond_to?( aSymbol, includePriv=false ) -> true or false Returns true if this object responds to the given method. Private methods are included in the search only if the optional second parameter evaluates to true.

Returns:
true if this responds to the given method !!! For some reason MRI shows the arity of respond_to? as -1, when it should be -2; that's why this is rest instead of required, optional = 1 Going back to splitting according to method arity. MRI is wrong about most of these anyway, and since we have arity splitting in both the compiler and the interpreter, the performance benefit is important for this method.

respond_to_p

public RubyBoolean respond_to_p(IRubyObject mname,
                                IRubyObject includePrivate)
obj_respond_to respond_to?( aSymbol, includePriv=false ) -> true or false Returns true if this object responds to the given method. Private methods are included in the search only if the optional second parameter evaluates to true.

Returns:
true if this responds to the given method !!! For some reason MRI shows the arity of respond_to? as -1, when it should be -2; that's why this is rest instead of required, optional = 1 Going back to splitting according to method arity. MRI is wrong about most of these anyway, and since we have arity splitting in both the compiler and the interpreter, the performance benefit is important for this method.

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
Overrides:
id in class RubyBasicObject
Returns:

id_deprecated

public IRubyObject id_deprecated()
rb_obj_id_obsolete Old id version. This one is bound to the "id" name and will emit a deprecation warning.


hash

public RubyFixnum hash()
rb_obj_id Will return the hash code of this object. In comparison to MRI, this method will use the Java identity hash code instead of using rb_obj_id, since the usage of id in JRuby will incur the cost of some. ObjectSpace maintenance.


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.

Overrides:
hashCode in class java.lang.Object

type

public RubyClass type()
rb_obj_class Returns the real class of this object, excluding any singleton/meta class in the inheritance chain.


type_deprecated

public RubyClass type_deprecated()
rb_obj_type The deprecated version of type, that emits a deprecation warning.


rbClone

public IRubyObject rbClone()
rb_obj_clone This method should be overridden only by: Proc, Method, UnboundedMethod, Binding. It will use the defined allocated of the object, then clone the singleton class, taint the object, call initCopy and then copy frozen state.

Specified by:
rbClone in interface IRubyObject
Overrides:
rbClone in class RubyBasicObject
Returns:
IRubyObject

dup

public IRubyObject dup()
rb_obj_dup This method should be overridden only by: Proc Will allocate a new instance of the real class of this object, and then initialize that copy. It's different from rbClone() in that it doesn't copy the singleton class.

Specified by:
dup in interface IRubyObject
Overrides:
dup in class RubyBasicObject
Returns:

display

public IRubyObject display(ThreadContext context,
                           IRubyObject[] args)
rb_obj_display call-seq: obj.display(port=$>) => nil Prints obj on the given port (default $>). Equivalent to: def display(port=$>) port.write self end For example: 1.display "cat".display [ 4, 5, 6 ].display puts produces: 1cat456


tainted_p

public RubyBoolean tainted_p(ThreadContext context)
rb_obj_tainted call-seq: obj.tainted? => true or false Returns true if the object is tainted.


taint

public IRubyObject taint(ThreadContext context)
rb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the $SAFE level is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.


untaint

public IRubyObject untaint(ThreadContext context)
rb_obj_untaint call-seq: obj.untaint => obj Removes the taint from obj. Only callable in if more secure than 3.


freeze

public IRubyObject freeze(ThreadContext context)
rb_obj_freeze call-seq: obj.freeze => obj Prevents further modifications to obj. A TypeError will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also Object#frozen?. a = [ "a", "b", "c" ] a.freeze a << "z" produces: prog.rb:3:in `<<': can't modify frozen array (TypeError) from prog.rb:3


frozen_p

public RubyBoolean frozen_p(ThreadContext context)
rb_obj_frozen_p call-seq: obj.frozen? => true or false Returns the freeze status of obj. a = [ "a", "b", "c" ] a.freeze #=> ["a", "b", "c"] a.frozen? #=> true


untrusted_p

public RubyBoolean untrusted_p(ThreadContext context)
rb_obj_untrusted call-seq: obj.untrusted? => true or false Returns true if the object is untrusted.


untrust

public IRubyObject untrust(ThreadContext context)
rb_obj_untrust call-seq: obj.untrust -> obj Marks obj as untrusted.


trust

public IRubyObject trust(ThreadContext context)
rb_obj_trust call-seq: obj.trust => obj Removes the untrusted mark from obj.


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
Overrides:
inspect in class RubyBasicObject
Returns:
String

instance_of_p

public RubyBoolean instance_of_p(ThreadContext context,
                                 IRubyObject type)
rb_obj_is_instance_of call-seq: obj.instance_of?(class) => true or false Returns true if obj is an instance of the given class. See also Object#kind_of?.


kind_of_p

public RubyBoolean 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 Returns true 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


methods

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


public_methods

public IRubyObject public_methods(ThreadContext context,
                                  IRubyObject[] args)
rb_obj_public_methods call-seq: obj.public_methods(all=true) => array Returns the list of public methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed.


protected_methods

public IRubyObject protected_methods(ThreadContext context,
                                     IRubyObject[] args)
rb_obj_protected_methods call-seq: obj.protected_methods(all=true) => array Returns the list of protected methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed. Internally this implementation uses the RubyModule.protected_instance_methods(org.jruby.runtime.builtin.IRubyObject[]) method.


private_methods

public IRubyObject private_methods(ThreadContext context,
                                   IRubyObject[] args)
rb_obj_private_methods call-seq: obj.private_methods(all=true) => array Returns the list of private methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed. Internally this implementation uses the RubyModule.private_instance_methods(org.jruby.runtime.builtin.IRubyObject[]) method.


singleton_methods

public RubyArray singleton_methods(ThreadContext context,
                                   IRubyObject[] args)
rb_obj_singleton_methods call-seq: obj.singleton_methods(all=true) => array Returns an array of the names of singleton methods for obj. If the optional all parameter is true, the list will include methods in modules included in obj. module Other def three() end end class Single def Single.four() end end a = Single.new def a.one() end class << a include Other def two() end end Single.singleton_methods #=> ["four"] a.singleton_methods(false) #=> ["two", "one"] a.singleton_methods #=> ["two", "one", "three"]


singleton_methods19

public RubyArray singleton_methods19(ThreadContext context,
                                     IRubyObject[] args)

singletonMethods

public RubyArray singletonMethods(ThreadContext context,
                                  IRubyObject[] args,
                                  boolean asSymbols)

method

public IRubyObject method(IRubyObject symbol)
rb_obj_method call-seq: obj.method(sym) => method Looks up the named method as a receiver in obj, returning a Method object (or raising NameError). The Method object acts as a closure in obj's object instance, so instance variables and the value of self remain available. class Demo def initialize(n)


to_s

public IRubyObject to_s()
rb_any_to_s call-seq: obj.to_s => string Returns a string representing obj. The default to_s prints the object's class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby programs returns ``main.''


to_a

public RubyArray to_a()
rb_any_to_a call-seq: obj.to_a -> anArray Returns an array representation of obj. For objects of class Object and others that don't explicitly override the method, the return value is an array containing self. However, this latter behavior will soon be obsolete. self.to_a #=> -:1: warning: default `to_a' will be obsolete "hello".to_a #=> ["hello"] Time.new.to_a #=> [39, 54, 8, 9, 4, 2003, 3, 99, true, "CDT"] The default to_a method is deprecated.


instance_eval

public IRubyObject instance_eval(ThreadContext context,
                                 Block block)
rb_obj_instance_eval call-seq: obj.instance_eval(string [, filename [, lineno]] ) => obj obj.instance_eval {| | block } => obj Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (_obj_). In order to set the context, the variable +self+ is set to _obj_ while the code is executing, giving the code access to _obj_'s instance variables. In the version of instance_eval that takes a +String+, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors. class Klass def initialize


instance_eval

public IRubyObject instance_eval(ThreadContext context,
                                 IRubyObject arg0,
                                 Block block)

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

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


instance_exec

public IRubyObject 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_). 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


extend

public IRubyObject 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. 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) #=> # k.hello #=> "Hello from Mod.\n"


initialize

public IRubyObject initialize()
rb_obj_dummy Default initialize method. This one gets defined in some other place as a Ruby method.


send

public IRubyObject send(ThreadContext context,
                        Block block)
rb_f_send send( aSymbol [, args ]* ) -> anObject Invokes the method identified by aSymbol, passing it any arguments specified. You can use __send__ if the name send clashes with an existing method in this object.
 class Klass
   def hello(*args)
     "Hello " + args.join(' ')
   end
 end

 k = Klass.new
 k.send :hello, "gentle", "readers"
 

Returns:
the result of invoking the method identified by aSymbol.

send

public IRubyObject send(ThreadContext context,
                        IRubyObject arg0,
                        Block block)

send

public IRubyObject send(ThreadContext context,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        Block block)

send

public IRubyObject send(ThreadContext context,
                        IRubyObject arg0,
                        IRubyObject arg1,
                        IRubyObject arg2,
                        Block block)

send

public IRubyObject send(ThreadContext context,
                        IRubyObject[] args,
                        Block block)

nil_p

public IRubyObject nil_p(ThreadContext context)
rb_false call_seq: nil.nil? => true .nil? => false Only the object nil responds true to nil?.


op_match

public IRubyObject op_match(ThreadContext context,
                            IRubyObject arg)
rb_obj_pattern_match call-seq: obj =~ other => false Pattern Match---Overridden by descendents (notably Regexp and String) to provide meaningful pattern-match semantics.


to_java

public IRubyObject to_java()

as

public IRubyObject as(java.lang.Class javaClass)

instance_variable_defined_p

public IRubyObject instance_variable_defined_p(ThreadContext context,
                                               IRubyObject name)
rb_obj_ivar_defined call-seq: obj.instance_variable_defined?(symbol) => true or false Returns true if the given instance variable is defined in obj. class Fred def initialize(p1, p2)


instance_variable_get

public IRubyObject 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. The @ part of the variable name should be included for regular instance variables. Throws a NameError exception if the supplied symbol is not valid as an instance variable name. class Fred def initialize(p1, p2)


instance_variable_set

public IRubyObject 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. The variable did not have to exist prior to this call. class Fred def initialize(p1, p2)


remove_instance_variable

public IRubyObject 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. class Dummy attr_reader :var def initialize


instance_variables

public RubyArray instance_variables(ThreadContext context)
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


validateInstanceVariable

protected java.lang.String validateInstanceVariable(java.lang.String name)
Checks if the name parameter represents a legal instance variable name, and otherwise throws a Ruby NameError



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