From: "David A. Black" Date: 2005-02-05T22:11:44+09:00 Subject: Re: iteration the ruby way Hi -- On Sat, 5 Feb 2005, E S wrote: > >> >> "William James" >> Aihe: Re: iteration the ruby way >> >> >> E S wrote: >> >>> ary[0..-1].each {|e| do_something(e) } >>> do_something_else(ary.last) >> >> Shouldn't that be >> >> ary[0...-1].each {|e| do_something(e) } >> do_something_else(ary.last) >> >> or >> >> ary[0..-2].each {|e| do_something(e) } >> do_something_else(ary.last) >> >> ? > > Yes, or indeed, it was actually supposed to be ary[0...-1] :) (I think that's what William just said :-) > In either case, as expected, the #inject-solution was superior. It's very interesting and could be useful, but where possible I'd tend to prefer the ary[0...-1] technique, or the #each_[with]_index one. They're shorter and, to me, somewhat more transparent. But I'm certainly not complaining about the development of the #inject one, which is something I would probably never have come up with. David -- David A. Black dblack@wobblini.net