Undefine variable in Ruby

local-variables, metaprogramming, ruby

Solution

There are remove_class_variable, remove_instance_variable and remove_const methods but there is currently no equivalent for local variables.

Problem

Let's say I'm using `irb`, and type `a = 5`. How do I remove the definition of `a` so that typing `a` returns a `NameError`? Some context: later I want to do this: ``` context = Proc.new{}.binding context.eval 'a = 5' context.eval 'undef a' # though this doesn't work. ```

Original source