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?
on 2006-06-02 01:39
on 2006-06-02 04:31
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. T.
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?