struct RBasic {
VALUE flags;
const VALUE klass;
};
struct RObject {
struct RBasic basic;
long numiv;
VALUE *ivptr;
// ...
};
struct RClass {
struct RBasic basic;
VALUE super;
rb_classext_t *ptr;
struct method_table_wrapper *m_tbl_wrapper;
};
class pointer
array of instance variables
object
method definitions
super pointer
Method definition table in class can contain only one "kind" of methods, instance methods, where are class methods?
Class methods or Ruby lookup in different place?
Are class methods language feature or is there a way to "describe those class objects"(meta)?
*** object DON'T have methods, classes DO ***
class Object
def my_describing_class
class << self; self; end
end
end
$> Class.singleton_class
=> #<Class:Class>
$> irb
$> ObjectSpace.count_objects[:T_CLASS]
=> 961
$> class User; end; ObjectSpace.count_objects[:T_CLASS]
=> 963
VALUE rb_class_real(VALUE cl)
{
while (cl && ((RBASIC(cl)->flags & FL_SINGLETON))
cl = RCLASS_SUPER(cl);
return cl;
}
VALUE rb_obj_class(VALUE obj)
{
return rb_class_real(CLASS_OF(obj));
}