From: Robert Klemme Date: 2007-07-17T23:12:30+09:00 Subject: Re: Are we cool? method_missing in enumerator 2007/7/17, Trans : > Can anyone demonstrate problems with the following? > > # Adds immediate elementwise ability to Enumerator. > # Any non-enumeration method is passed on to each. > # > # [1,2,3].to_enum(:map) + 3 > # => [4,5,6] > # > # Note there may be a few essential methods this can not > # be used on, such as #object_id. > > class Enumerable::Enumerator > def method_missing(sym,*args,&blk) > each{ |x| x.send(sym,*args,&blk) } > end > end > > I like the simplicity of this and would rather use it than add an > another class layer, but I need to be sure I'm not overlooking any > potential dangers with doing so. Cool indeed! The only thing that comes to mind at the moment is a certain inconsistency that this creates: all methods implemented in the Enumerator are methods operating on the collection while methods invoked by your extension are invoked per instance in the collection. I am not sure whether that actually disqualifies the change as a std lib change... Btw, your sample would be equally simple by doing [1,2,3].map {|x| x+3} - it's even less typing. ;-) Kind regards robert