From: Yukihiro Matsumoto Date: 2005-07-07T02:19:43+09:00 Subject: Re: Inheriting Array and slice() behaviour Hi, In message "Re: Inheriting Array and slice() behaviour" on Wed, 6 Jul 2005 18:17:21 +0900, Sylvain Joyeux writes: |I have a class inheriting Array, and I expected slice() and [] |to return Array objects. Why? I'd expect them to return instances of the class of the receiver, as Daniel does in [ruby-talk:147323], since they are ripped part of the receiver. |Moreover, since my Expression class has instance variables, the instance |produced by slice() does not have it anymore (which is bad) I agree that is bad. It might be possible to call initialize() at the time of sub-array allocation, at the cost of performance. Besides that, we have to make consensus for how initialize() will be called for those sub-array. Anyway, I'd suggest you not to subclass basic classes, unless you are sure what you're doing. I don't think Expressions by no means have is-a relationship to Arrays. Inheritance is not a panacea. matz.