From: Robert Klemme Date: 2010-12-01T06:40:45+09:00 Subject: Re: Object#each ? On 11/30/2010 06:45 PM, Andrew Wagner wrote: > On Tue, Nov 30, 2010 at 12:44 PM, Andrew Wagnerwrote: > >> A weird idea just popped into my head: >> >> class Object >> def each >> yield self >> end >> end >> >> Lets you enumerate without having to worry about whether or not you have a >> collection. Thoughts? Hidden ramifications? First of all if you implement #each then you should also include Enumerable because the expectation would be that you also have all the nice methods like #select, #map etc. This makes all objects Enumerable which does not seem a good idea. One drawback of this approach is that you won't notice if you accidentally pass something to a method which should be Enumerable (I mean a real collection) - or at least the issue might take some time to be detected. > Ugh, did I just say collection? I thought my .Net days were behind me....I > meant, of course, an enumerable... :-) Cheers robert