From: Daniel Brockman Date: 2005-07-13T01:59:44+09:00 Subject: Re: accessing index inside map nobu.nokada@softhome.net writes: > Hi, > > At Wed, 13 Jul 2005 01:10:19 +0900, > Brian Candler wrote in [ruby-talk:147876]: >> However, perhaps 'to_enum' could be called something friendlier, e.g. >> >> obj.using(:each_with_index).inject(0) {|sum,(a,i)| sum + a*i} > > `using' sounds too general. > >> In fact, even >> >> obj.enum(:each_with_index).inject(0) {|sum,(a,i)| sum + a*i} >> >> reads better to me, as it's not stressing the creation of an intermediate >> object. to_foo looks like you are converting obj into something completely >> different, rather than just adding a temporary wrapper. > > Enumerable#to_enum has an alias named as #enum_for. How about just `for'? That word is already strongly associated with enumeration, and connects well to the `each_*'. obj.for(:each_with_index).inject(0) { |sum, (a, i)| sum + a * i } However, ``for each inject'' sounds pretty weird, since we're not injecting something into each element --- we're injecting it into the whole collection. I don't know, just a thought. -- Daniel Brockman