Change class of existing object?

Hi All,

I was wondering whether it’s at all possible to change the class of an
already existing object. This is purely theoretical, so forgive me if
this is against all the best practices.

As a hint, what I have in mind is something along the lines of Perl’s
(yes, indeed…) bless() function.

Thanks,

-Max


MLB.com: Where Baseball is Always On

Hi –

On Thu, 2 Nov 2006, Afonov, Max wrote:

Hi All,

I was wondering whether it’s at all possible to change the class of
an already existing object. This is purely theoretical, so forgive
me if this is against all the best practices.

No, an object retains its “birth class” forever. I think there might
be some 3vi1 libraries out there that manage to bring this about :slight_smile:
But the basic design is that the class doesn’t change. (Of course you
can change literally everything about the object’s actual behavior,
what methods it has, etc.).

David

On Thu, 2 Nov 2006, Afonov, Max wrote:

I was wondering whether it’s at all possible to change the class of
an already existing object. This is purely theoretical, so forgive
me if this is against all the best practices.

Depending upon your need you may also find that delegate may be helpful:

http://www.ruby-doc.org/stdlib/libdoc/delegate/rdoc/index.html

pth