# Change class of existing object?

**URL:** <https://rubytalk.org/t/change-class-of-existing-object/32580>\
**Category:** ruby-talk\
**Created:** [2 November 2006 02:04 UTC](https://rubytalk.org/t/change-class-of-existing-object/32580 "2006-11-02T02:04:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Afonov\_Max](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Afonov\_Max](https://rubytalk.org/u/Afonov_Max)\
**Post date:** [2 November 2006 02:04 UTC](https://rubytalk.org/t/change-class-of-existing-object/32580/1 "2006-11-02T02:04:07Z")

</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:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [2 November 2006 02:09 UTC](https://rubytalk.org/t/change-class-of-existing-object/32580/2 "2006-11-02T02:09:00Z")

</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
> 
> --  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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](http://www.manning.com/black) | [3] [http://www.rubypowerandlight.com](http://www.rubypowerandlight.com)  
> [2] [http://dablog.rubypal.com](http://dablog.rubypal.com) | [4] [http://www.rubycentral.org](http://www.rubycentral.org)

---

<div class="post-metadata">

**Author:** ![Patrick\_Hurley1](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@Patrick\_Hurley1](https://rubytalk.org/u/Patrick_Hurley1)\
**Post date:** [2 November 2006 13:06 UTC](https://rubytalk.org/t/change-class-of-existing-object/32580/3 "2006-11-02T13:06:30Z")

</div>

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

> **···**
>
> > 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.
