From: Ryan Paul Date: 2004-05-15T19:38:50+09:00 Subject: Re: changing class at runtime On Sat, 15 May 2004 09:48:02 +0000, gabriele renzi wrote: > il Sat, 15 May 2004 07:47:03 GMT, Ryan Paul > ha scritto:: > >>I'm trying to find a way to arbitrarily alter the class of an instance at >>runtime. The documentation didn't appear to have any clues. >> >>Ultimately, I want to be able to do something like this: > > > > Can I dare to ask why you need this? > I discovere stuff like runtime change of class and #become just with > the Evil library, then found that this was possible in other > languages. > But I wonder what is this useful for ? > > I don't have a clue on what you're doing but could not you just extend > the object at runtime with some mixins ? At the moment, I have no actual reason for wanting to do this in ruby. I have used it several times in python, mainly to work around problems in poorly designed oo libraries. I imagine that ruby's superior support for class extension, and a few other more graceful facets of the language nullify the necessity of hacks like this, but its nice to know that I can do it if I ever need to. Honestly, I asked for the sake of finding out if ruby could do it, more than for the sake of actually being able to. I like to keep options open, and being able to manipulate the class like that gives me yet another way to solve a potential problem in the future. Incidentally, perusing the content of the 'evil' library has provided me with some fascinating insights about some of the advanced features of the language, so in that respect, it has already proven itself to be valuable.