From: Tim Hunter Date: 2003-02-11T23:18:40+09:00 Subject: Re: inheriting from base classes The ImageList class in RMagick is a subclass of Array. An ImageList is an array of images, plus an index value that addresses the "current" image. Yes, there's a "looseness of fit." There's a handful of methods that just don't apply to an array of images: to_s, pack, etc. Since by definition an ImageList can only contain images, assoc, flatten, and such-like also don't apply. These methods are undefined in ImageList. There's a method in ImageList for every Array method. Array methods that return Arrays (+, for example) call "self.class.new.replace" to convert the Arrays that the super returns into ImageLists. (Yes, ImageList#replace gets a lot of work.) Adding an Array to an ImageList works, as long as the array contains only images, and yields an ImageList. Adding an ImageList to an Array yields an Array, which is what I think you'd expect. My first cut at ImageList had ImageList _contain_ an array of images and the usual accessor methods for the array, but this was just too clunky. For example, mylist.images << newimage is clunky compared to mylist << newimage On Tue, 11 Feb 2003 11:40:14 +0900, dblack@candle.superlink.net wrote: > >We're both very interested in hearing what people's views are on this. >Do you ever subclass String, Array, and Hash? Do you specifically >avoid doing so? >