From: "David A. Black" Date: 2005-02-01T04:34:59+09:00 Subject: Re: Array::uniq { block } ? Hi -- On Tue, 1 Feb 2005, Florian Gross wrote: > Robert Klemme wrote: > >> Also (as optimization) you could use "state << item" instead of "state + >> [item]" because Array#<< returns self. This saves you a lot temporary >> 1element arrays and avoids creating new arrays all the time (Array#+ >> creates a new Array). :-) > > I dislike having the block of .inject having side effects. That sort of > defeats the purpose IMHO. I don't think it's a side effect, since it's just injecting something into the accumulator or "injectee". This might be exactly what you want if, for example, you have multiple references to the accumulator: x = [] y = x ["a","b","c"].inject(x) {|m,n| m << n.upcase} puts y # ["A", "B", "C"] Otherwise in a case like this you could just use #map. David -- David A. Black dblack@wobblini.net