When I simply remove the class using remove_const it will still be
available via the ObjectSpace though, so that doesn't really work :/


Basically I want this test to pass:

class Foo
end

# removing the class somehow

ObjectSpace.each_object(Class) do |klass|
    assert !(Foo > klass)
end


On 10/20/05, Ryan Leavengood <leavengood / gmail.com> wrote:
> On 10/20/05, Florian Weber <csshsh / gmail.com> wrote:
> > Hi!
> >
> > Is there a way to remove a class for good from the ObjectSpace? I
> > would like to redefine a class entirely without any 'leftovers' of the
> > previous definition.
>
> Here is something to think about:
>
> class Module
>   def flush(klass)
>     remove_const(klass.name.intern)
>   end
> end
>
> class Foo
> end
>
> f = Foo.new
> p f
>
> Object.flush(Foo)
>
> p Object.const_defined?(:Foo)
> f2 = Foo.new # Causes exception
> __END__
>
> The object referred to by variable f will remain in the object space
> until you set f to nil and start the GC (or let it run on its own.)
>
> Ryan
>
>