From: shiwei zhang Date: 2006-11-14T19:53:58+09:00 Subject: Re: Getting initialization status from "foo = Class.new" ------=_Part_113674_9569743.1163501634292 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, Rodney, I wrote a small program for you, maybe it can meet your requirements. I think you intended that your program flow could be controled directly by "foo = Class.new" instead of other dedicated variables like "@found" for this purpose. //////////////////////program commences/////////////////////// class ClassAndFileTest def initialize puts "shiwei zhang"; #searching the file........... #if found the file ; #if did not find the file raise "file not found!"; end end begin foo=ClassAndFileTest.new; rescue #give error message puts $!; exit; end # continue program puts "file found!"; ............ /////////////////////////program concludes//////////////////////////// Rgds, Shiwei On 11/13/06, Rodney Brown wrote: > > Here's a ruby noob question for ya: > > I have a class I've made that the initalize method searches for a file > needed for the class to function. > > Right now, I've made a class variable, "found", that is set to true or > false if the initialize method could or could not find the file. > > For example: > > foo = Class.new > > if foo.found == true > # continue program > else > # give error message > exit > > Is there a way for "Class.new" to signal failure? I originally had the > class's initialize method return true or false but this doesn't seem to > be reflected in a "foo = Class.new" when trying it in irb. > > Using the class variable "found" works but shouldn't Class.new signal > failure? > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_113674_9569743.1163501634292--