Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroy a variable in ruby [duplicate]

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.

like image 370
Miguel Beltrán Avatar asked Nov 02 '25 03:11

Miguel Beltrán


1 Answers

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

like image 108
Agis Avatar answered Nov 04 '25 04:11

Agis