Forum: Ruby Forcing superclass initialization

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ara V. (Guest)
on 2006-06-02 01:39
So if the a negligent subclass refuses to call its superclass initialize
method, instance variables in the superclass may not get initialized.
Not a good thing. Is there some way to force the superclass method to
get called?
unknown (Guest)
on 2006-06-02 04:31
(Received via mailing list)
Actually I find that an interesting question. I've sometimes wondered
about "forced super" for #initialize, as well and all methods actually.
The problem though is at least two fold.

1) How do you "override". What if the behavior needs to be completely
different and you want none of what comes before?

2) A forced super has to be called at some specific point. Should it be
before eveything else, or after? What if you want things to occur
before and after?

In the past I've suggested that a better appraoch would be either AOP
on the ::new call --if we ever get a bonafide AOP system. Or at least a
"preinitialize" callback in which there is a "forced" execution
throughout the class hierarchy.

Ara V. (Guest)
on 2006-06-02 18:59
yes, those are good points. Ideal would be callbacks right after the
object was created or right before. And then there's the issue of the
order of initialization within the inheritance hierarchy. I was
wondering if there was a primitive solution in implementing a callback
for whenever a new instance of any object is created, checking to see
its type, and performing initialization if it is one of those classes
which has registered for mandatory initialization. But I do not know
where in the Ruby APIsuch a callback exists.

is there some philosophical reason the Ruby community is against this?
This topic is locked and can not be replied to.