From: Shugo Maeda Date: 2001-04-27T11:40:06+09:00 Subject: [ruby-talk:14287] Re: how change instances class At Fri, 27 Apr 2001 03:20:06 +0900, Henning VON ROSEN wrote: > Say, that a instance at first is known as belonging to a fairly general class,�and when > we gather more information, it turns out to belong more precisely to a subclass. > > Is this part of Ruby 'as is', or do I have to extend. Point is to keep instance id, > while the knowledge of which class it belongs to�changes. Just like in real world as > reflected in human language. (Changing to a subclass�might be readily accepted, while > changing to�an unrelated class would demand an admittance that the first guess was an > error.) I think it is dangerous to change classes of instances. Do you really need it? You can extend objects with mixin modules. class Person ... end module Runnable def run ... end end person = Person.new person.extend(Runnable) person.run > (2) How do I delete�(un-mix) a mixin? I don't know how to delete a mixin, but undef or undef_method may be useful. class Runner include Runnable end class RetiredRunner undef run end Shugo