From: Yukihiro Matsumoto Date: 2005-07-07T08:42:37+09:00 Subject: Re: Inheriting Array and slice() behaviour Hi, In message "Re: Inheriting Array and slice() behaviour" on Thu, 7 Jul 2005 07:54:17 +0900, William Morgan writes: |> 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. | |But #+ returns an Array. Is that consistent? The result from + method is not a sub-array. Where X = A + B, the possible choices of the class of X are: (a) assured common ancestor, i.e. Array (b) lowest common ancestor of A and B (c) class of A if A and B are instances of same class, Array otherwise Currently (a) is my decision. (b) is too expensive, I guess. (c) might be a good choice, but I'm not sure whether it's more useful than the current one. |Like the OP, I think it's weird and special-cased to have #slice |magically return something with the receiver's class. Especially since |the return value is going to be broken (not initialized) except in |trivial cases. What if it can be initialized properly? matz.