|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jruby.RubyBasicObject
org.jruby.RubyObject
public class RubyObject
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()
.
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 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 java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final ObjectAllocator OBJECT_ALLOCATOR
ObjectAllocator
Constructor Detail |
---|
public RubyObject(Ruby runtime, RubyClass metaClass)
public RubyObject(RubyClass metaClass)
protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted)
protected RubyObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace)
Method Detail |
---|
public static RubyClass createObjectClass(Ruby runtime, RubyClass objectClass)
public void attachToObjectSpace()
ObjectSpace
public int getNativeTypeIndex()
getNativeTypeIndex
in interface CoreObjectType
getNativeTypeIndex
in class RubyBasicObject
org.jruby.runtime.ClassInde
public static void puts(java.lang.Object obj)
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
protected void checkFrozen()
RubyBasicObject.testFrozen(java.lang.String)
.
public final void callInit(IRubyObject[] args, Block block)
@Deprecated public final IRubyObject convertToType(RubyClass target, int convertMethodIndex)
@Deprecated public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject[] args, Block block)
public IRubyObject specificEval(ThreadContext context, RubyModule mod, Block block)
public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg, Block block)
public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, Block block)
public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
public IRubyObject evalUnder(ThreadContext context, RubyModule under, IRubyObject src, IRubyObject file, IRubyObject line)
public IRubyObject evalUnder(ThreadContext context, RubyModule under, RubyString src, java.lang.String file, int line)
public IRubyObject op_equal(ThreadContext context, IRubyObject obj)
op_equal
in interface IRubyObject
op_equal
in class RubyBasicObject
public IRubyObject equal_p(ThreadContext context, IRubyObject obj)
public IRubyObject eql_p(IRubyObject obj)
public IRubyObject op_eqq(ThreadContext context, IRubyObject other)
op_eqq
in interface IRubyObject
op_eqq
in class RubyBasicObject
protected static boolean equalInternal(ThreadContext context, IRubyObject that, IRubyObject other)
protected static boolean eqlInternal(ThreadContext context, IRubyObject that, IRubyObject other)
public IRubyObject initialize_copy(IRubyObject original)
public RubyBoolean respond_to_p(IRubyObject mname)
public RubyBoolean respond_to_p(IRubyObject mname, IRubyObject includePrivate)
public IRubyObject id()
id
in interface IRubyObject
id
in class RubyBasicObject
public IRubyObject id_deprecated()
public RubyFixnum hash()
public int hashCode()
hashCode
in class java.lang.Object
public RubyClass type()
public RubyClass type_deprecated()
public IRubyObject rbClone()
rbClone
in interface IRubyObject
rbClone
in class RubyBasicObject
public IRubyObject dup()
rbClone()
in that it doesn't copy the singleton class.
dup
in interface IRubyObject
dup
in class RubyBasicObject
public IRubyObject display(ThreadContext context, IRubyObject[] args)
$>
).
Equivalent to:
def display(port=$>)
port.write self
end
For example:
1.display
"cat".display
[ 4, 5, 6 ].display
puts
produces:
1cat456
public RubyBoolean tainted_p(ThreadContext context)
true
if the object is tainted.
public IRubyObject taint(ThreadContext context)
$SAFE
level is
set appropriately, many method calls which might alter the running
programs environment will refuse to accept tainted strings.
public IRubyObject untaint(ThreadContext context)
public IRubyObject freeze(ThreadContext context)
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
public RubyBoolean frozen_p(ThreadContext context)
public RubyBoolean untrusted_p(ThreadContext context)
true
if the object is untrusted.
public IRubyObject untrust(ThreadContext context)
public IRubyObject trust(ThreadContext context)
public IRubyObject inspect()
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"
inspect
in interface IRubyObject
inspect
in class RubyBasicObject
public RubyBoolean instance_of_p(ThreadContext context, IRubyObject type)
true
if obj is an instance of the given
class. See also Object#kind_of?
.
public RubyBoolean kind_of_p(ThreadContext context, IRubyObject type)
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
public IRubyObject methods(ThreadContext context, IRubyObject[] args)
public IRubyObject public_methods(ThreadContext context, IRubyObject[] args)
false
, only those methods
in the receiver will be listed.
public IRubyObject protected_methods(ThreadContext context, IRubyObject[] args)
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.
public IRubyObject private_methods(ThreadContext context, IRubyObject[] args)
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.
public RubyArray singleton_methods(ThreadContext context, IRubyObject[] args)
public RubyArray singleton_methods19(ThreadContext context, IRubyObject[] args)
public RubyArray singletonMethods(ThreadContext context, IRubyObject[] args, boolean asSymbols)
public IRubyObject method(IRubyObject symbol)
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)
public IRubyObject to_s()
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.''
public RubyArray to_a()
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.
public IRubyObject instance_eval(ThreadContext context, Block block)
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
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, Block block)
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block)
public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
@Deprecated public IRubyObject instance_eval(ThreadContext context, IRubyObject[] args, Block block)
public IRubyObject instance_exec(ThreadContext context, IRubyObject[] args, Block block)
public IRubyObject extend(IRubyObject[] args)
public IRubyObject initialize()
public IRubyObject send(ThreadContext context, Block block)
class Klass def hello(*args) "Hello " + args.join(' ') end end k = Klass.new k.send :hello, "gentle", "readers"
public IRubyObject send(ThreadContext context, IRubyObject arg0, Block block)
public IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block)
public IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
public IRubyObject send(ThreadContext context, IRubyObject[] args, Block block)
public IRubyObject nil_p(ThreadContext context)
true
to nil?
.
public IRubyObject op_match(ThreadContext context, IRubyObject arg)
Regexp
and String
) to provide meaningful
pattern-match semantics.
public IRubyObject to_java()
public IRubyObject as(java.lang.Class javaClass)
public IRubyObject instance_variable_defined_p(ThreadContext context, IRubyObject name)
true
if the given instance variable is
defined in obj.
class Fred
def initialize(p1, p2)
public IRubyObject instance_variable_get(ThreadContext context, IRubyObject name)
@
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)
public IRubyObject instance_variable_set(IRubyObject name, IRubyObject value)
public IRubyObject remove_instance_variable(ThreadContext context, IRubyObject name, Block block)
public RubyArray instance_variables(ThreadContext context)
protected java.lang.String validateInstanceVariable(java.lang.String name)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |