Xavier Noria
11/12/2006 10:40:00 PM
On Nov 11, 2006, at 9:55 PM, Xavier Noria wrote:
> which removes the basename of the class we want to remove from the
> constants in its parent module, if any. The irb session below
> suggests that technique triggers a "fresh" reload of the class, but
> why? A posteriori one would bet a class definition reopens the
> class if there's already a class object in that constant, and just
> instantiates a new one otherwise, is that right?
I reply to myself :-). Looking at the source code in class.c that's
indeed the case:
VALUE
rb_define_class(name, super)
const char *name;
VALUE super;
{
VALUE klass;
ID id;
id = rb_intern(name);
if (rb_const_defined(rb_cObject, id)) {
klass = rb_const_get(rb_cObject, id);
...
return klass;
}
...
klass = rb_define_class_id(id, super);
...
return klass;
}
Understood!
-- fxn