From: Bruce Woodward Date: 2006-04-13T21:00:57+09:00 Subject: Re: map_if, collect_if ??? ------=_Part_18679_28063859.1144929652562 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ara, Thanks for your reply. I have been using inject but shyed away in this case because for the 'real' code that I have been working on I am actually already using an accumualtor. So I had; acc =3D [] array.each { |v| condition_expression and acc << v.attribute } Using inject seems to be roughly equivalent. In the example above v is a instance of the Struct class. cheers, Bruce. On 4/12/06, ara.t.howard@noaa.gov wrote: > > On Thu, 13 Apr 2006, Bruce Woodward wrote: > > > a =3D [ 1,2,3,4,5 ] > > > > b =3D a.map_if { |i| > > (i % 2 !=3D 0) and (i * 10) > > } > > > > p b ## [10, 30, 50] > > inject is very powerfull: > > harp:~ > cat a.rb > a =3D 1 .. 5 > b =3D a.inject([]){|a,i| i[0] =3D=3D 1 ? a.push(i * 10) : a} > p b > > harp:~ > ruby a.rb > [10, 30, 50] > > regards. > > -a > -- > be kind whenever possible... it is always possible. > - h.h. the 14th dali lama > > ------=_Part_18679_28063859.1144929652562--