From: Robert Klemme Date: 2005-07-07T06:35:45+09:00 Subject: Re: Inheriting Array and slice() behaviour William Morgan wrote: > Excerpts from Sylvain Joyeux's mail of 6 Jul 2005 (EDT): >>> What return type do you want? Arrays or Expressions? You can force >>> return values back to Arrays with #to_a, or manually make >>> Expressions with something like >>> >>> y = Expression.new(x.slice(1..5).to_a) >> >> I find it VERY weird to build anything else than an Array here. Array >> now nothing about Expression, so I don't see how - in general - it >> could build a well-formed Expression object > > I agree with you. I think this is bad behavior. I wouldn't be so certain of this. It's normal for operations like #dup and #clone to behave that way. Also, part of the smartness of ruby is that you can simply do self.class.new to get a new instance of the same class. And often you need to create an instance of the same class. That's not too abnormal. IMHO if there is a problem then with proper initialization of the new instance. OTOH, inheriting classes like Array is seldom really good. There are too many methods that return plain arrays and you end up with Arrays anyway. Delegation, ad hoc modification or extension with a Module is often better. Kind regards robert