Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Public Member Functions | Protected Member Functions | List of all members
Rice::Object Class Reference

The base class for all Objects. More...

#include <Object_defn.hpp>

Inheritance diagram for Rice::Object:
Rice::Builtin_Object< RArray, T_ARRAY > Rice::Builtin_Object< RHash, T_HASH > Rice::Builtin_Object< RString, T_STRING > Rice::Builtin_Object< RStruct, T_STRUCT > Rice::Builtin_Object< T, Builtin_Type > Rice::Data_Object< T > Rice::Exception_Base Rice::Module_base Rice::Symbol

Public Member Functions

 Object (VALUE value=Qnil)
 Encapsulate an existing ruby object.
 
 Object (Object const &other)
 Copy constructor.
 
virtual ~Object ()
 Destructor.
 
bool test () const
 
 operator bool () const
 
bool is_nil () const
 Returns true if the object is nil, false otherwise.
 
 operator VALUE () const
 Implicit conversion to VALUE.
 
VALUE const volatile & value () const
 Explicitly get the encapsulated VALUE.
 
Class class_of () const
 Get the class of an object. More...
 
int compare (Object const &other) const
 Compare this object to another object. More...
 
String to_s () const
 Return a string representation of an object. More...
 
String inspect () const
 Inspect the object. More...
 
void freeze ()
 Freeze the object.
 
bool is_frozen () const
 Determine if the object is frozen. More...
 
void swap (Object &other)
 Swap with another Object.
 
Object instance_eval (String const &s)
 Evaluate the given string in the context of the object. More...
 
int rb_type () const
 Return the type of the underlying C object. More...
 
bool is_a (Object klass) const
 Determine whether the object is an instance of a class/module. More...
 
bool respond_to (Identifier id) const
 Determine if the objects responds to a method. More...
 
bool is_instance_of (Object klass) const
 Determine whether class is the object's class. More...
 
template<typename T >
void iv_set (Identifier name, T const &value)
 Set an instance variable. More...
 
Object iv_get (Identifier name) const
 Get the value of an instance variable. More...
 
Object attr_get (Identifier name) const
 Get the value of an instance variable, but don't warn if it is. More...
 
template<typename Retval_T >
Retval_T call (Identifier id, T1 arg1, T2 arg2,...) const
 Call the Ruby method specified by 'id' on object 'obj'. More...
 
Object call (Identifier id, T1 arg1, T2 arg2,...) const
 Version of call which defaults to Object return type.
 
Object vcall (Identifier id, Array args)
 Vectorized call. More...
 
void mark () const
 Mark the object with the garbage collector.
 

Protected Member Functions

void set_value (VALUE v)
 Set the encapsulated value.
 

Detailed Description

The base class for all Objects.

Perhaps the name "Object" is a misnomer, because this class really holds an object reference, not an object.

Examples:
enum/sample_enum.cpp, and map/map.cpp.

Member Function Documentation

Object Rice::Object::attr_get ( Identifier  name) const

Get the value of an instance variable, but don't warn if it is.

Parameters
namethe name of the instance variable to get
Returns
the value of the instance variable
template<typename Retval_T >
Retval_T Rice::Object::call ( Identifier  id,
T1  arg1,
T2  arg2,
  ... 
) const

Call the Ruby method specified by 'id' on object 'obj'.

Pass in arguments (arg1, arg2, ...). The arguments will be converted to Ruby objects with to_ruby<>. The return value will automatically be converted to type Retval_T with from_ruby<>.

E.g.:

* float y = x.call<float>("foo", z, 42);
*
Examples:
map/map.cpp.
Class Rice::Object::class_of ( ) const

Get the class of an object.

Returns
the object's Class.
int Rice::Object::compare ( Object const &  other) const

Compare this object to another object.

Gets the result of self <=> other and returns the result. The result will be less than zero if self < other, greater than zero if self > other, and equal to zero if self == other.

String Rice::Object::inspect ( ) const

Inspect the object.

Returns
the result of calling inspect on the object. A String is not returned, because it is not possible to return an instance of a derived class.
Object Rice::Object::instance_eval ( String const &  s)

Evaluate the given string in the context of the object.

This is equivalant to calling obj.instance_eval(s) from inside the interpreter.

Returns
the result of the expression.
bool Rice::Object::is_a ( Object  klass) const

Determine whether the object is an instance of a class/module.

Parameters
klassa class or module.
Returns
true if the object is an instance of the given class/module or one of its descendants.
bool Rice::Object::is_frozen ( ) const

Determine if the object is frozen.

Returns
true if the object is frozen, false otherwise.
bool Rice::Object::is_instance_of ( Object  klass) const

Determine whether class is the object's class.

Parameters
klassa class.
Returns
true if the object is an instance of the given class.
Object Rice::Object::iv_get ( Identifier  name) const

Get the value of an instance variable.

Parameters
namethe name of the instance variable to get
Returns
the value of the instance variable
template<typename T >
void Rice::Object::iv_set ( Identifier  name,
T const &  value 
)

Set an instance variable.

Parameters
namethe name of the instance variable to set (including the leading @ sign)
valuethe value of the variable, which will be converted to a Ruby type if necessary.
Rice::Object::operator bool ( ) const
inline

Returns false if the object is nil or false; returns true otherwise.

References test().

int Rice::Object::rb_type ( ) const

Return the type of the underlying C object.

This is equivalent to calling rb_type(obj).

Returns
the type of the underlying C object (e.g. T_DATA, T_ARRAY, etc.).
bool Rice::Object::respond_to ( Identifier  id) const

Determine if the objects responds to a method.

Parameters
idthe name of the method
Returns
true if the objects responds to the method, false otherwise.
bool Rice::Object::test ( ) const
inline

Returns false if the object is nil or false; returns true otherwise.

Examples:
map/map.cpp.

Referenced by operator bool().

String Rice::Object::to_s ( ) const

Return a string representation of an object.

Returns
the result of calling to_s on the object. A String is not returned, because it is not possible to return an instance of a derived class.
Object Rice::Object::vcall ( Identifier  id,
Array  args 
)

Vectorized call.

Calls the method identified by id with the list of arguments identified by args.

Parameters
idthe name of the method to call
argsthe arguments to the method
Returns
the return value of the method call

The documentation for this class was generated from the following files: