[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: Re: undefining Class.inherited makes class not subclassable anymore
From: Tilman Sauerbeck <tilman () code-monkey ! de>
Date: 2006-02-18 10:31:05
Message-ID: 20060218103031.GA2668 () code-monkey ! de
[Download RAW message or body]
dblack [2006-02-15 7:38]:
> > 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.
Thanks, rb_remove_method() does the trick :)
Regards,
Tilman
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[Attachment #3 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic