From: Ben Giddings Date: 2004-06-15T00:17:55+09:00 Subject: Re: undefine tony summerfelt wrote: > in my particular case i'm thinking black box approach. i don't want > the variable to 'exist' any more. > > i don't know if that's how it's thought of in perl, but when i > undef($x), $x is no longer there for me to use unless i assign it > something, and i can test that it isn't with: > > if ! defined($x) # do something. > > as long as ruby 'acts' the same way, it's all i need. I think the best way to get the behaviour you want is to use a hash. Instead of assigning the value to a variable, you just assign the value to a hash key. $h = Hash.new def test_key(sym) if $h.has_key?(sym) ... else ... end end test_key(:foo) $h[:foo] = "Bar" test_key(:foo) $h.delete(:foo) test_key(:foo) Now if you don't use .has_key? and you just try to access the hash entry, you'll just get 'nil' back (by default at least). If you want to have an exception raised instead, that's doable too. Ben