From: "David A. Black" Date: 2009-08-29T18:50:30+09:00 Subject: Re: #map, #select semantics --1926193751-1685737034-1251539415=:30937 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1685737034-1251539415=:30937" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1685737034-1251539415=:30937 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Sat, 29 Aug 2009, 7rans wrote: > > > 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. I don't mean that *something* can't be defined for every class; I mean specifically that it will never be the case that every Enumerable class will return an instance of itself from its iterations. David -- David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com Ruby/Rails training, mentoring, consulting, code-review Latest book: The Well-Grounded Rubyist (http://www.manning.com/black2) September Ruby training in NJ has been POSTPONED. Details to follow. --1926193751-1685737034-1251539415=:30937-- --1926193751-1685737034-1251539415=:30937--