From: William Morgan Date: 2005-07-08T02:27:27+09:00 Subject: Re: Inheriting Array and slice() behaviour Excerpts from Robert Klemme's mail of 6 Jul 2005 (EDT): > 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. Dup and clone work on objects that have already been initialized. Self.class.new is done explicitly, so that's fine too---if the constructor has required arguments, you supply them at that point. My problem with Array#slice is that the objects created will never have #initialize called. Indeed, they never *can* have it called, because who knows what arguments need to be supplied. > 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. I agree that it's seldom a good idea (and it certainly wasn't in this case). But sometimes it could be the right thing to do. -- William