Sunday, August 2, 2009

How to tell if a ruby variable is already set.

Use the 'defined?' command to determine if a variable has already been set in a ruby script.

e.g. alpha = 'A' unless (defined?(alpha))

set the value of alpha to be 'A' unless it's already set. Yes, there are other shorter ways to do this particular. But, the example is still relevant.

No comments:

Post a Comment