From: Robert Dober Date: 2010-11-02T04:51:51+09:00 Subject: Re: the dark side of inherited methods On Mon, Nov 1, 2010 at 12:49 AM, James Edward Gray II wrote: > On Oct 31, 2010, at 5:30 PM, timr wrote: > It is a problem with inheritance and another reason why inheritance is almost never what we want. Completely agree with this. Apart of the code you suggested I would like to tackle the problem on a conceptional level. Enumerable#map returns arrays Period. What OP might want to do is something like this module Sequence include Enumerable # A sequence is defined by # (i) How to traverse it # def each &blk # making sure that blk is called with exactly all elements of the sequence in the # predefined order # (ii) How to append elements to it # def add new_element # creating a new sequence (or modifying in place) def map &blk inject(self.class.new) do | result, ele | result.add blk.( ele ) end end end # module Sequence If OP had had this available the delegation would have worked quite well. class Vector include Sequence def each; # as he needs (must yield all elements) def add; # as he needs (must return a Sequence) No inheritance and yet quite some effective decomposition :P HTH R. -- There are worse things than having people misunderstand your work. A worse danger is that you will yourself misunderstand your work. -- Paul Graham