From: Yusuke ENDOH Date: 2009-12-11T01:55:35+09:00 Subject: [ruby-core:27133] Re: #to_enum ignores block? Hi, 2009/12/11 Roger Pack : >> ... >> or if you REALLY wanted those results: >> >> ruby-1.9.1-p376 > (1..3).map {|n| n**2} >> => [1, 4, 9] > > Oops well assuming the operation is correct--it's because I want an > enumerator, not an array. I really understand what you want to do. But unfortunately, current Ruby does not support the feature directly. So I made a simple library: http://mamememo.blogspot.com/2009/11/enumerablerrb-enumerable-lazy-version.html http://d.hatena.ne.jp/ku-ma-me/20091111/p2 (in Japanese) Matz said that these methods are acceptable to be embedded into the core, but did not accept their names (selector, mapper, etc.). Instead, Matz suggested enum_select, enum_map, etc., but I dislike them because they are too verbose. Now I'm thinking that it is good for all Enumerable's methods (including map and select) to return an Enumerator instead of an Array. Yes, this is a big change of the spec. The change should wait until 2.0 even if it is accepted, >> As far as I can tell, standard Ruby Enumerable#to_enum never took a block > > Older builds of 1.9.0 did, or so I am told [1]. > > Currently one can roll one's own "filter" block if desired, I was just > wondering if it was a "slip up" to remove the functionality or not. I > assume it wasn't, but just wanted to double check. According to the commit log, it seemed to be "an undocumented feature", and was removed intentionally. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=16146 -- Yusuke ENDOH