I’m tinkering with an application that has multiple ruby shells against
which code can be executed (with instance_eval), and I’m trying to
“undefine” a class that has been previously defined in one of the
shells. I understand that normally you would invoke the “remove_const”
method via a “send”, but I’m getting a “not defined” error. I think
perhaps Object is not the appropriate destination for the “send” when
the class was defined within an “instance_eval”, but I’m stumped on
figuring this out further.
Below is a reduced set of code that reproduces the problem. Thanks in
advance for any assistance.
class Shell; end
s = Shell.new()
s.instance_eval( <<EOS )
class Test
def a; puts “method a”; end
end
o = Test.new()
o.a()
EOS
s.instance_eval( <<EOS )
puts Test.superclass # Object, so class Test does exist at this point
Object.send( :remove_const, :Test ) # throws error: constant
Object::Test not defined (NameError)
EOS