Russell Fulton wrote:
> Russell Fulton wrote:
>>
>> I have tried both dup and clone to copy the default objects but I always 
>> seem to end up with the original object in host.
>> 
> 
> More investigations reveals that the objects are being at least 
> partially copied. 'simple' variables (strings etc) are copied by arrays 
> are not.
> 
> I have managed to work around this by adding a method fix to the class 
> which reinitalised the instance arrays to [] and fix'ing the newly 
> dup'ed instances.
> 
> This appears to be a bug in ruby.  I'll see if I can reproduce it in a 
> small program.

OK, not a bug but a feature.  My copy of the pickaxe was at home and I 
now understand that dup and clone only do shallow copies.  I'm wondering 
if I can use initialize_copy to copy the arrays that I need -- it is 
described as a call back -- do I just define a method of that name and 
it will be called on copy?  I'll just have to suck and see!

To Rick who was curious about the anonymous classes.  Yes they are 
anonymous, this program is a log scanner and I generate a class for each 
host in the config file with its own scanner and alert routine to 
process logs.   I read the config file then generate the scanner 
routines on the fly using eval. I'm not sure why I made them anonymous 
they don't have to be and I may well change it.  The code is in svn on 
rubyforge in the selms project.  I'll be updating it soon and doing the 
first beta release in a week or so.  I need to do a short web page 
before I get to that point - bloody documentations ;)

Thanks to those who responded to my post :)  I did google this but 
clearly not very effectively!

Russell

-- 
Posted via http://www.ruby-forum.com/.