Getting initialization status from "foo = Class.new"

R

Rodney Brown

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?
 
T

Timothy Hunter

Rodney said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,219
Messages
2,571,117
Members
47,727
Latest member
PasqualePf

Latest Threads

Top