From: jayce@... (Jayce Piel) Date: 2002-04-05T16:33:40+09:00 Subject: Re: Test the result of an initialization ? FreeMan wrote: > Jayce Piel wrote: > > > Ok, so that is near to the same problem that testing argument before > > the call to #new... :-/ > > By putting begin/rescue code around all call to #new, the code begins > > to be unreadable... > > my understanding is that you want something like that : > -- > $arch = ArchiveFile.new('filename') > -- > > with $arch being nil if filename doesn't exist. In this case, it's if filename doesn't exist... In my code, it is for some more reasons... In fact, $arch should be nil if there is an error (wrong filename, wrong archive type, archive corrupted....) in the initialization. > if i'm right then you're going to have to test if it's nil before doing > anything with it ... > and that's not really more readable than the rescue code. It is : - I can test if it is nil when I need, and I don't have to test just here. - In the object concept, it is not "good" to have an inconsistent object. I have valid objects or I have nil... - The object is responsible of its creation. Users of an object doesn't have to know what is good or not for this object. -- Jayce Piel ( jayce@mosx.net ) Site Web sur MacOS X (Server) en fran�ais : Pourquoi il ne faut pas activer le compte root ? R�ponse :