From: "David A. Black" Date: 2004-07-03T02:59:52+09:00 Subject: Re: How to detect if variable has been defined yet? Hi -- On Sat, 3 Jul 2004, gabriele renzi wrote: > il Fri, 02 Jul 2004 17:40:40 GMT, Randy Lawrence > ha scritto:: > > > defined? may be useful. Anyway, writing: > > if variable > variable+=1 > else > variable=0 > end > > should do just fine > Have you tried it? :-) $ ruby if variable; variable += 1; else variable = 0; end ^D -:1: undefined local variable or method `variable' for main:Object (NameError) I think you'd have to use defined?, or conditionally initialize the variable: x ||= 0 x += 1 (Note that you can't condense that into (x ||= 0) += 1, though you could do: x = (x ||= 0) + 1 ) David -- David A. Black dblack@wobblini.net