From: David Flanagan Date: 2008-06-12T03:59:27+09:00 Subject: [ruby-core:17225] Re: Enumerable::Enumerator#with_memo David A. Black wrote: >> I'm beginning to feel that the method we're discussing here is one >> particular member of a set of methods for defining custom iterations. >> Imagine something like: >> >> a1.each.with_index.and_next_of(a2).and_const(a3).and_returning([]) do >> |elt1, index, elt2, a3, retval| >> end >> >> Or: >> >> [1,2,3].each.alternating_with([4,5,6]).and_returning([]) {|x,ret|...} >> >> Does anyone like the use of "and" instead of "with" to indicate the >> addition of a new value to be passed to the block? > > I don't particularly. But then again, I'm not a fan of lots of > chaining that tries to make things sound like English narrative. It > never really does, and I just lose track of it in the Ruby part of my > brain. That's why, as much as I respect the talent and effort behind > it, I can't use RSpec. > > > David > I took the chaining examples over the top here on purpose. I doubt they'd actually get used like that very often. But it is worth pointing out that chained invocations are implicit in this style of looping with enumerators. As in each.with_index and each.with_memo, for example. I was just taking this a step further. And it raises again the question of whether there should be an each_with_memo method directly on Enumerable instead of or in addition to with_memo on Enumerator. I believe that Matz has plans for Enumerators in Ruby 2.0 and I'm really beginning to feel that with_memo ought to be postponed and reconsidered in the context of Ruby 2.0 David Flanagan