From: Brian Candler Date: 2005-07-12T19:02:30+09:00 Subject: Re: accessing index inside map > IMHO the enumerator approach is slightly superior as your suggestion can > lead to conflicts with current method arguments as you have noticed. > Personally I don't have a problem using > > a.to_enum(:each_with_index).inject(0) {|sum,(a,i)| sum + a*i} > > I think this is more flexible and modularized. And the overhead of a new > instance creation is usually neglectible compared to the iteration > overhead. "Do the simplest thing which will possibly work" :-) Actually I think my version reads better: a.inject(0,:each_with_index) {|sum,(a,i)| sum + a*i} "Starting with 0, call :each_with_index with the following block". Regards, Brian.