From: jayce@... (Jayce Piel) Date: 2002-04-05T16:33:41+09:00 Subject: Re: Test the result of an initialization ? Luc Heinrich wrote: > On 4/04/2002 18:52, "Jayce Piel" wrote: > > > By putting begin/rescue code around all call to #new, the code begins to > > be unreadable... > > Uh, that's highly debatable, but I won't bite (at least not here)... ;-) Ok, where and when you want... Choose your weapon... ;-) > Anyway, if you *really* want to use the 'return-nil-on-error' creation > pattern, why don't you use a factory method in your class ? Like... Yes it's an idea... > class ArchiveFile > > private_class_method :new > > def ArchiveFile.create( name ) > return new(name) if (name.is_valid_and_stuff?) > return nil > end > ... > end But... Why not redefine the #new method then ? It's more "transparent"... > .. which: > 1. Ensure that the block is executed *only* if the parameter is valid. Ok. > 2. Automatically close the archive file when the block ends. I don't need this... open/close is dealed in another method. > 3. Looks much nicer... :-) Humph... > And on a more general note, you really shouldn't try to apply patterns or > idioms from other languages when Ruby have a specific (and usually better > :-) ) approach. One way ? One think ? One language ?..... :-) Think different !!! :-))))))) -- 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 :