org.jruby
Class RubyObject

java.lang.Object
  extended byorg.jruby.RubyObject
All Implemented Interfaces:
java.lang.Cloneable, IRubyObject
Direct Known Subclasses:
FileStatClass, JavaCallable, JavaClass, JavaField, JavaObject, Method, Mutex, RubyArgsFile, RubyArray, RubyBoolean, RubyDir, RubyException, RubyHash, RubyIO, RubyMatchData, RubyModule, RubyNumeric, RubyProc, RubyRange, RubyRegexp, RubyString, RubyStruct, RubySymbol, RubyTime, ThreadClass

public class RubyObject
extends java.lang.Object
implements java.lang.Cloneable, IRubyObject

Author:
jpetersen

Field Summary
protected  Ruby runtime
           
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyObject(Ruby ruby)
           
RubyObject(Ruby ruby, RubyClass rubyClass)
           
RubyObject(Ruby ruby, RubyClass rubyClass, boolean useObjectSpace)
           
 
Method Summary
 int argCount(IRubyObject[] args, int min, int max)
          Method argCount.
 java.lang.String asSymbol()
          rb_to_id
protected  CallbackFactory callbackFactory()
           
 void callInit(IRubyObject[] args)
           
 IRubyObject callMethod(java.lang.String name)
          Method funcall.
 IRubyObject callMethod(java.lang.String name, IRubyObject arg)
          rb_funcall
 IRubyObject callMethod(java.lang.String name, IRubyObject[] args)
          rb_funcall2
 void checkSafeString()
          Method checkSafeString.
 IRubyObject convertToString()
           
 IRubyObject convertToType(java.lang.String targetType, java.lang.String convertMethod, boolean raise)
          Converts this object to type 'targetType' using 'convertMethod' method.
 IRubyObject convertType(java.lang.Class type, java.lang.String targetType, java.lang.String convertMethod)
          rb_convert_type
static void createObjectClass(RubyClass module)
           
 void defineSingletonMethod(java.lang.String name, Callback method)
          rb_define_singleton_method
 IRubyObject display(IRubyObject[] args)
           
 IRubyObject dup()
          rb_obj_dup
 RubyBoolean equal(IRubyObject obj)
          rb_obj_equal
 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 eval(INode n)
          rb_eval
 IRubyObject eval(IRubyObject src, IRubyObject scope, java.lang.String file, int line)
          Method eval.
 IRubyObject evalUnder(RubyModule under, IRubyObject src, IRubyObject file, IRubyObject line)
           
 IRubyObject extend(IRubyObject[] args)
           
 void extendObject(RubyModule module)
          Method extendObject.
 IRubyObject freeze()
          Freeze an object.
 RubyBoolean frozen()
          rb_obj_frozen_p
 IRubyObject getInstanceVariable(java.lang.String name)
          rb_iv_get / rb_ivar_get
 java.util.Map getInstanceVariables()
           
 java.lang.Class getJavaClass()
          Method getJavaClass.
 RubyClass getMetaClass()
          if exist return the meta-class else return the type of the object.
 Ruby getRuntime()
          Getter for property ruby.
 RubyClass getSingletonClass()
          rb_singleton_class
 RubyClass getType()
          Method getType.
 RubyFixnum hash()
           
 int hashCode()
          hashCode() is just a wrapper around Ruby's hash() method, so that Ruby objects can be used in Java collections.
 boolean hasInstanceVariable(java.lang.String name)
          Method isInstanceVarDefined.
 RubyFixnum id()
          Return the internal id of an object.
protected  void infectBy(IRubyObject obj)
          OBJ_INFECT
 RubyString inspect()
          rb_obj_inspect
 IRubyObject instance_eval(IRubyObject[] args)
           
 RubyBoolean instance_of(IRubyObject type)
          rb_obj_is_instance_of
 RubyArray instance_variables()
           
 java.util.Iterator instanceVariableNames()
           
 boolean isFalse()
           
 boolean isFrozen()
          Gets the frozen.
 boolean isKindOf(RubyModule type)
          Method isKindOf.
 boolean isNil()
          Method isNil.
 boolean isTaint()
          Gets the taint.
 boolean isTrue()
           
 RubyBoolean kind_of(IRubyObject type)
          rb_obj_is_kind_of
 MetaClass makeMetaClass(RubyClass type)
          Create a new meta class.
 void marshalTo(MarshalStream output)
          Method marshalTo.
 IRubyObject method_missing(IRubyObject[] args)
          Method method_missing.
 IRubyObject method(IRubyObject symbol)
           
 IRubyObject methods()
          rb_obj_methods
static IRubyObject nilObject(Ruby ruby)
           
 IRubyObject private_methods()
          rb_obj_private_methods
 IRubyObject protected_methods()
          rb_obj_protected_methods
 IRubyObject rbClone()
          rb_obj_clone
 IRubyObject removeInstanceVariable(java.lang.String name)
           
 RubyBoolean respond_to(IRubyObject[] args)
          respond_to?( aSymbol, includePriv=false ) -> true or false Returns true if this object responds to the given method.
 boolean respondsTo(java.lang.String name)
          Method respondsTo.
 IRubyObject send(IRubyObject[] args)
          send( aSymbol [, args ]* ) -> anObject Invokes the method identified by aSymbol, passing it any arguments specified.
 void setFrozen(boolean frozen)
          Sets the frozen.
 IRubyObject setInstanceVariable(java.lang.String name, IRubyObject value)
          rb_iv_set / rb_ivar_set
 IRubyObject setInstanceVariable(java.lang.String name, IRubyObject value, java.lang.String taintError, java.lang.String freezeError)
           
 void setInstanceVariables(java.util.Map instanceVariables)
           
 void setMetaClass(RubyClass metaClass)
           
 void setTaint(boolean taint)
          Sets the taint.
 void setupClone(IRubyObject obj)
          CLONESETUP
 RubyArray singleton_methods()
          rb_obj_singleton_methods
 boolean singletonMethodsAllowed()
           
 IRubyObject specificEval(RubyModule mod, IRubyObject[] args)
          specific_eval
 IRubyObject taint()
          rb_obj_taint
 RubyBoolean tainted()
          rb_obj_tainted
 RubyArray to_a()
           
 RubyString to_s()
           
 java.lang.String toString()
           
 RubyClass type()
          rb_obj_type
 IRubyObject untaint()
          rb_obj_untaint
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

runtime

protected transient Ruby runtime
Constructor Detail

RubyObject

public RubyObject(Ruby ruby)

RubyObject

public RubyObject(Ruby ruby,
                  RubyClass rubyClass)

RubyObject

public RubyObject(Ruby ruby,
                  RubyClass rubyClass,
                  boolean useObjectSpace)
Method Detail

nilObject

public static IRubyObject nilObject(Ruby ruby)

makeMetaClass

public MetaClass makeMetaClass(RubyClass type)
Create a new meta class.

Since:
Ruby 1.6.7

singletonMethodsAllowed

public boolean singletonMethodsAllowed()
Specified by:
singletonMethodsAllowed in interface IRubyObject

getJavaClass

public java.lang.Class getJavaClass()
Description copied from interface: IRubyObject
Method getJavaClass.

Specified by:
getJavaClass in interface IRubyObject
Returns:
Class

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.


toString

public java.lang.String toString()

getRuntime

public Ruby getRuntime()
Getter for property ruby.

Specified by:
getRuntime in interface IRubyObject
Returns:
Value of property ruby.

hasInstanceVariable

public boolean hasInstanceVariable(java.lang.String name)
Description copied from interface: IRubyObject
Method isInstanceVarDefined.

Specified by:
hasInstanceVariable in interface IRubyObject
Parameters:
name -
Returns:
boolean

removeInstanceVariable

public IRubyObject removeInstanceVariable(java.lang.String name)

getInstanceVariables

public java.util.Map getInstanceVariables()

setInstanceVariables

public void setInstanceVariables(java.util.Map instanceVariables)

getMetaClass

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

Specified by:
getMetaClass in interface IRubyObject

setMetaClass

public void setMetaClass(RubyClass metaClass)
Specified by:
setMetaClass in interface IRubyObject

isFrozen

public boolean isFrozen()
Gets the frozen.

Specified by:
isFrozen in interface IRubyObject
Returns:
Returns a boolean

setFrozen

public void setFrozen(boolean frozen)
Sets the frozen.

Specified by:
setFrozen in interface IRubyObject
Parameters:
frozen - The frozen to set

isTaint

public boolean isTaint()
Gets the taint.

Specified by:
isTaint in interface IRubyObject
Returns:
Returns a boolean

setTaint

public void setTaint(boolean taint)
Sets the taint.

Specified by:
setTaint in interface IRubyObject
Parameters:
taint - The taint to set

isNil

public boolean isNil()
Description copied from interface: IRubyObject
Method isNil.

Specified by:
isNil in interface IRubyObject
Returns:
boolean

isTrue

public boolean isTrue()
Specified by:
isTrue in interface IRubyObject

isFalse

public boolean isFalse()

respondsTo

public boolean respondsTo(java.lang.String name)
Description copied from interface: IRubyObject
Method respondsTo.

Specified by:
respondsTo in interface IRubyObject
Parameters:
name -
Returns:
boolean

argCount

public int argCount(IRubyObject[] args,
                    int min,
                    int max)
Description copied from interface: IRubyObject
Method argCount.

Specified by:
argCount in interface IRubyObject
Parameters:
args -
min -
max -
Returns:
int

isKindOf

public boolean isKindOf(RubyModule type)
Description copied from interface: IRubyObject
Method isKindOf.

Specified by:
isKindOf in interface IRubyObject
Parameters:
type -
Returns:
boolean

getSingletonClass

public RubyClass getSingletonClass()
rb_singleton_class

Specified by:
getSingletonClass in interface IRubyObject
Returns:
RubyClass

defineSingletonMethod

public void defineSingletonMethod(java.lang.String name,
                                  Callback method)
rb_define_singleton_method

Specified by:
defineSingletonMethod in interface IRubyObject
Parameters:
name -
method -

setupClone

public void setupClone(IRubyObject obj)
CLONESETUP

Specified by:
setupClone in interface IRubyObject
Parameters:
obj -

infectBy

protected void infectBy(IRubyObject obj)
OBJ_INFECT


callMethod

public IRubyObject callMethod(java.lang.String name,
                              IRubyObject[] args)
rb_funcall2

Specified by:
callMethod in interface IRubyObject
Parameters:
name -
args -
Returns:
IRubyObject

callMethod

public IRubyObject callMethod(java.lang.String name)
Description copied from interface: IRubyObject
Method funcall.

Specified by:
callMethod in interface IRubyObject
Parameters:
name -
Returns:
RubyObject

callMethod

public IRubyObject callMethod(java.lang.String name,
                              IRubyObject arg)
rb_funcall

Specified by:
callMethod in interface IRubyObject
Parameters:
name -
arg -
Returns:
RubyObject

getInstanceVariable

public IRubyObject getInstanceVariable(java.lang.String name)
rb_iv_get / rb_ivar_get

Specified by:
getInstanceVariable in interface IRubyObject
Parameters:
name -
Returns:
RubyObject

setInstanceVariable

public IRubyObject setInstanceVariable(java.lang.String name,
                                       IRubyObject value,
                                       java.lang.String taintError,
                                       java.lang.String freezeError)

setInstanceVariable

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

Specified by:
setInstanceVariable in interface IRubyObject
Parameters:
name -
value -
Returns:
RubyObject

instanceVariableNames

public java.util.Iterator instanceVariableNames()

eval

public IRubyObject eval(INode n)
rb_eval

Specified by:
eval in interface IRubyObject
Parameters:
n -
Returns:
IRubyObject

callInit

public void callInit(IRubyObject[] args)
Specified by:
callInit in interface IRubyObject

extendObject

public void extendObject(RubyModule module)
Description copied from interface: IRubyObject
Method extendObject.

Specified by:
extendObject in interface IRubyObject
Parameters:
module -

asSymbol

public java.lang.String asSymbol()
rb_to_id

Specified by:
asSymbol in interface IRubyObject
Returns:
String the symbol name

convertToType

public IRubyObject convertToType(java.lang.String targetType,
                                 java.lang.String convertMethod,
                                 boolean raise)
Converts this object to type 'targetType' using 'convertMethod' method. MRI: convert_type

Specified by:
convertToType in interface IRubyObject
Parameters:
targetType -
convertMethod -
raise -
Since:
Ruby 1.6.7.

convertToString

public IRubyObject convertToString()
Specified by:
convertToString in interface IRubyObject

convertType

public IRubyObject convertType(java.lang.Class type,
                               java.lang.String targetType,
                               java.lang.String convertMethod)
rb_convert_type

Specified by:
convertType in interface IRubyObject
Parameters:
type -
targetType -
convertMethod -

checkSafeString

public void checkSafeString()
Description copied from interface: IRubyObject
Method checkSafeString.

Specified by:
checkSafeString in interface IRubyObject

specificEval

public IRubyObject specificEval(RubyModule mod,
                                IRubyObject[] args)
specific_eval


evalUnder

public IRubyObject evalUnder(RubyModule under,
                             IRubyObject src,
                             IRubyObject file,
                             IRubyObject line)

eval

public IRubyObject eval(IRubyObject src,
                        IRubyObject scope,
                        java.lang.String file,
                        int line)
Description copied from interface: IRubyObject
Method eval.

Specified by:
eval in interface IRubyObject
Parameters:
src -
scope -
file -
line -
Returns:
IRubyObject

equal

public RubyBoolean equal(IRubyObject obj)
rb_obj_equal


respond_to

public RubyBoolean respond_to(IRubyObject[] args)
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

id

public RubyFixnum id()
Return the internal id of an object. Warning: In JRuby there is no guarantee that two objects have different ids. CRuby function: rb_obj_id


hash

public RubyFixnum hash()

hashCode

public final int hashCode()
hashCode() is just a wrapper around Ruby's hash() method, so that Ruby objects can be used in Java collections.


type

public RubyClass type()
rb_obj_type


rbClone

public IRubyObject rbClone()
rb_obj_clone

Specified by:
rbClone in interface IRubyObject
Returns:
IRubyObject

display

public IRubyObject display(IRubyObject[] args)

dup

public IRubyObject dup()
rb_obj_dup

Specified by:
dup in interface IRubyObject

tainted

public RubyBoolean tainted()
rb_obj_tainted


taint

public IRubyObject taint()
rb_obj_taint


untaint

public IRubyObject untaint()
rb_obj_untaint


freeze

public IRubyObject freeze()
Freeze an object. rb_obj_freeze


frozen

public RubyBoolean frozen()
rb_obj_frozen_p


inspect

public RubyString inspect()
rb_obj_inspect

Specified by:
inspect in interface IRubyObject
Returns:
String

instance_of

public RubyBoolean instance_of(IRubyObject type)
rb_obj_is_instance_of


instance_variables

public RubyArray instance_variables()

kind_of

public RubyBoolean kind_of(IRubyObject type)
rb_obj_is_kind_of


methods

public IRubyObject methods()
rb_obj_methods


protected_methods

public IRubyObject protected_methods()
rb_obj_protected_methods


private_methods

public IRubyObject private_methods()
rb_obj_private_methods


singleton_methods

public RubyArray singleton_methods()
rb_obj_singleton_methods


method

public IRubyObject method(IRubyObject symbol)

to_a

public RubyArray to_a()

to_s

public RubyString to_s()

instance_eval

public IRubyObject instance_eval(IRubyObject[] args)

extend

public IRubyObject extend(IRubyObject[] args)

method_missing

public IRubyObject method_missing(IRubyObject[] args)
Description copied from interface: IRubyObject
Method method_missing.

Specified by:
method_missing in interface IRubyObject
Parameters:
args -
Returns:
IRubyObject

send

public IRubyObject send(IRubyObject[] args)
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.

marshalTo

public void marshalTo(MarshalStream output)
               throws java.io.IOException
Description copied from interface: IRubyObject
Method marshalTo.

Specified by:
marshalTo in interface IRubyObject
Parameters:
output -
Throws:
java.io.IOException

getType

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

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

callbackFactory

protected CallbackFactory callbackFactory()

createObjectClass

public static void createObjectClass(RubyClass module)


Copyright © 2002 Jan Arne Petersen. All Rights Reserved.