On Friday 10 August 2001 06:41 am,  Guy Decoux wrote:
> >>>>> "N" == Ned Konz <ned / bike-nomad.com> writes:
>
> N> I think that's what I meant but didn't say. The new class has the
> original N> class as a superclass, right?
>
>  Yes, but you can't compare singleton classes with perl bless.

Of course. What I was saying is that "changing the class" effectively happens 
in Ruby when you provide an instance-specific method. But it's not a general 
purpose solution to class changing, since it leaves the object in its 
original inheritance graph (that is, its new uni-class is a subclass of its 
original one).

>  The equivalent of bless, in ruby, is just to change RBASIC(obj)->klass

Is there a way to do this safely in pure Ruby?

> and  perl don't have (natively) the equivalent of singleton classes.

Yes, that's why we wrote Class::Prototyped. Because of the simplicity of 
Perl's type system, it was easy to make up a new unique name for the 
singleton class (we based it on the object address). The singleton class then 
inherits behavior (and data, using closures) from its parent slots using 
Perl's multiple inheritance (the @ISA array).

It is a bit costly in terms of memory to do this (in Perl, anyway), as each 
new class gets a new symbol table and a method cache (for performance 
reasons). It costs about 1K for each new singleton class, almost 3K if you 
have two methods and two data slots.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned / bike-nomad.com
homepage:  http://bike-nomad.com