From: Graham Nicholls Date: 2004-07-06T16:37:49+09:00 Subject: Initialize returning nil if error condition - how I've got "The Ruby Way" & "Programming Ruby", but can't find out how to have an initializer return nil if theres a problem - something like this: Class Cover_file def initialize(fname) 64 @fname=fname 65 if $verbose 66 printf("Checking file %s\n",@fname) 67 end 68 # Parse filename for component parts (product,policy_no,site_no,schedule) 69 comp_patt=Regexp.compile(/^([A-Z]+)([0-9]+)([0-9][0-9] ([\w\d]+)\.en$/) 70 if @fname !~ comp_patt 71 if $verbose 72 printf("Sorry, %s does not match cover clause filename template\n",fname) 73 end 74 return nil If I try self=nil, I (not unreasonably - I expected it) get an error. What I want to do is this: cfile=Cover_file.new(fname) if cfile == nil some error handling end But I can't work out how. Thanks. Graham Nicholls -- With Linux, the answer's always "Yes"