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

--
                   David A. Black | dblack@wobblini.net
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

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

···

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.