From: Gary Wright Date: 2008-04-15T06:06:06+09:00 Subject: Re: How to duplicate a object changing the class without attributes memory copy On Apr 11, 2008, at 7:41 AM, Iņaki Baz Castillo wrote: > > At the beggining "headers_array" just contain "Header" objects but > after inspection I want to replace the header with @name='From' with a > "From" object but since "name" and "body" attributes are the same I > don't want a memory copy operation to allocate space for new object. > > This is: I just want to change the Class of a "Header" object to > "From" class, keeping the attributes without memory copy operation, is > there any way? I imagine in C I'd do it by using pointers. You can not change the class of an object in Ruby. You'll have to instantiate a new object and copy the attributes. If you just do something like: from_obj.name = header_obj.name You are simply copying object references, you aren't copying all the associated data. Gary Wright