From: dblack@... Date: 2006-02-15T07:38:47+09:00 Subject: Re: undefining Class.inherited makes class not subclassable anymore Hi -- On Wed, 15 Feb 2006, Tilman Sauerbeck wrote: > Hi, > 1.) cFoo = rb_define_class ("Foo", rb_cObject); > 2.) rb_define_singleton_method (cFoo, "inherited", ...) > 3.) rb_undef_method (rb_singleton_class (foo, "inherited")) > 4.) rb_define_class (c, "Bar", cFoo) > > The fourth call will lead to an error saying: > "Undefined method 'inherited'" > > Is there a way to restore the default Class.inherited method on Foo, so > I can still inherit from Foo, but not call the original inherited method > I defined in step 2? A semi-guess, but I think you could use rb_remove_method instead of rb_undef_method. On the Ruby side, at least (and I assume the C side), remove_method removes the method from the class or module but still allows earlier ones to be called, whereas undef_method causes instances (singleton or otherwise) not to be able to call the method at all. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black