Testing global variables for existence?

H

Hadmut Danisch

Hi,

I need to set a global variable (e.g. $configfile ) to a default value
if it has not been set before to anything else. In order to
not overwrite it I have to check whether it has been set previously.

$configfile.nil? would do the job, but ruby -w spits out a warning
that the variable has not yet been initialized.

How do I test whether the variable has been set without causing
ruby -w to print a warning in case it has not been set?

regards
Hadmut
 
T

ts

H> How do I test whether the variable has been set without causing
H> ruby -w to print a warning in case it has not been set?

With defined?

uln% ruby -we '$a = 12 unless defined?($a); p $a'
12
uln%



Guy Decoux
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top