From: Robert Klemme Date: 2007-07-17T16:08:26+09:00 Subject: Re: What is the fastest way to convert a object? 2007/7/17, Ryan Davis : > > On Jul 16, 2007, at 22:56 , Magicloud Magiclouds wrote: > > > Class Test > > def methodA > > puts(@var1) > > end > > def initialize > > @var1 = 0 > > end > > end > > > > obj = Object.new > > obj.instance_variable_set(:@var1, 2) > > > > > > # Now I want obj to be Test's instance, so I can > > obj.methodA > > # How to do this quickly? > > You don't. Ruby is strongly typed, which means that things don't just > "morph" into other types of things automatically or manually. > Specifically, you can't (without voodoo) set an instance's class. Adding to that: MM, what problem are you trying to solve? robert