# Change class of existing object?

**URL:** <https://www.ruby-forum.com/t/change-class-of-existing-object/74717>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:53am UTC](https://www.ruby-forum.com/t/change-class-of-existing-object/74717 "2006-11-07T10:53:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AfonovS\_Max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@AfonovS\_Max](https://www.ruby-forum.com/u/AfonovS_Max)\
**Post date:** [November 7, 2006, 10:53am UTC](https://www.ruby-forum.com/t/change-class-of-existing-object/74717/1 "2006-11-07T10:53:43Z")

</div>

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](http://MLB.com): Where Baseball is Always On

---

<div class="post-metadata">

**Author:** ![AfonovS\_Max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@AfonovS\_Max](https://www.ruby-forum.com/u/AfonovS_Max)\
**Post date:** [November 7, 2006, 10:53am UTC](https://www.ruby-forum.com/t/change-class-of-existing-object/74717/2 "2006-11-07T10:53:44Z")

</div>

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 🙂  
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

---

<div class="post-metadata">

**Author:** ![AfonovS\_Max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@AfonovS\_Max](https://www.ruby-forum.com/u/AfonovS_Max)\
**Post date:** [November 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/change-class-of-existing-object/74717/3 "2006-11-07T10:54:36Z")

</div>

> 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](http://www.ruby-doc.org/stdlib/libdoc/delegate/rdoc/index.html)

pth
