Overwriting (for real) a class

How can completely overwrite a class (not extend it)? For example.

fileA.rb:
class MyClass
def foo
end
end

fileB.rb (executed after fileA.rb):
class MyClass
def bar
end
end

MyClass.new.foo # I want a no method exception here

Thanks for the help.

Christopher J. Bottaro wrote:

How can completely overwrite a class (not extend it)?

MyClass = nil
class MyClass

end

Though you will get a warning for reassigning a constant. Or you could
do:
Object.send(:remove_const, :MyClass)
class MyClass

end

HTH,
Sebastian.

MyClass.new.foo # I want a no method exception here

You can remove methods (there is a private method Class#remove_method)
or remove the constant MyClass[1] and then define it anew. What would
be a sensible use case for this?

Thomas.

[1] Example:
http://groups.google.com/group/ruby-talk-google/msg/0fc850e23243d830

On Tue, Mar 04, 2008 at 04:34:56AM +0900, ThoML wrote:

You can remove methods (there is a private method Class#remove_method)
or remove the constant MyClass[1] and then define it anew. What would
be a sensible use case for this?

For security on Try Ruby, I remove any IO classes and methods. Some
are replaced with a mock filesystem even.

_why