From: Magicloud Magiclouds Date: 2007-07-17T17:33:58+09:00 Subject: Re: What is the fastest way to convert a object? Robert Klemme wrote: > 2007/7/17, Magicloud Magiclouds : >> Robert Klemme wrote: >> > 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 >> > >> > >> I am using DRb, and I have many data models need to be generated on >> server and sent to client. So I think a smaller object would be better. >> Right? > > Maybe, maybe not. Here are my 0.02 EUR: > > 1. I'd verify that "large" objects are really an issue > 2. I'd make conversion explicit by means ot a #to_xyz method, i.e. > receive an object and invoke obj.to_your_real_stuff on it. > > Kind regards > > robert > > Yes, this is my problem, too. I need an efficient way to transfer data model, but it seems that drb is not just "transfer". Even if I ignore the object size thing, still, calling a drbObject's complex method is an issue.