Search code examples
rubyvariablesdestroy

Destroy a variable in ruby


I want to destroy a variable in ruby as if it had never existed. Here is an example:

> defined? a
=> "nil"
> a = 1
> defined? a
=> "local-variable"

Now I need to set variable a to "nil" when I do defined?.

I tried some things like:

> a = nil #Not working
=> nil
> defined? a 
=>  "local-variable"

But nothing seems to work.


Solution

  • As of now (MRI 2.2 and before), there's no way to do this.