From: 7rans Date: 2009-08-29T13:50:35+09:00 Subject: Re: #map, #select semantics On Aug 28, 9:54 am, "David A. Black" wrote: > I guess I like the simplicity of defining each, including Enumerable, > and getting pre-defined behavior. I know that Hash and Array already > override a few things, though, so it's never been quite that simple. > Still, given the underlying mechanism, there's no way to generalize > returning a same-class object. Sure there is --or at least it can be made complete predictable. Just define a special class method, eg. class Array def self.enumerable_instance; []; end end class Hash def self.enumerable_instance; {}; end end Then a uniform "add". Eg. #<< (btw I love Hash#<<) and the whole thing can be generalized. This has been discussed before, but for whatever reason the idea has been disregarded. I suspect efficiency hacks have come to out way any of these nice "uniformalizaions". T.