[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting initialization status from "foo = Class.new"

Rodney Brown

11/13/2006 1:23:00 AM

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-....

2 Answers

Harold Hausman

11/13/2006 1:32:00 AM

0

On 11/13/06, Rodney Brown <rodney.brown@knology.net> wrote:
> 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?
>

How about raising an exception?
http://www.rubycentral.com/book/tut_excep...

-Harold

Tim Hunter

11/13/2006 2:53:00 AM

0

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?
>
>
Generally when the initialize method fails it should raise an exception.