From: Magicloud Magiclouds Date: 2007-07-17T16:27:08+09:00 Subject: Re: What is the fastest way to convert a object? Ryan Davis wrote: > > 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. > > > Would obj.extend(Test) work?