On 14 aoû¹, 20:33, Michael Libby <michael.c.li... / gmail.com> wrote: > On Thu, Aug 14, 2008 at 12:27 PM,Erwin<yves_duf... / mac.com> wrote: > > On 14 aoû¹, 19:24,Erwin<yves_duf... / mac.com> wrote: > >> I know there is DRY way tow rite that, but I don't remember how > > >> residence_rentals_ids = [] > >> residences = user.franchise.residences > >> or residence in residences > >> esidence_rentals_ids = residence.rentals.map {|rental| > >> rental[:id] }.compact > >> end > > >> I tried unsuccessfully : > > >> residence_rentals_ids = user.franchise.residences.each { |residence| > >> residence.rentals.map { |rental| rental[:id}.compact } > > >> thanks for your lights > > >>erwin > > > got it > > residence_rentals_ids = [] > > user.franchise.residences.each { |residence| residence.rentals.map { | > > rental| residence_rentals_ids << rental[:id] }.compact } > > > but is there a way to avoid the residence_rentals_ids = [] ine, > > including the array initialization into a block ? > > Generally you don't want a map without assigning the result to something. > > Does this do what you want? > > residence_rental_ids = user.franchise.residences.map{|residence| > residence.rentals.map{|rental| rental[:id] } }.flatten > > -Michael that's it... thanks a lot.. I was missing the .flatten functionality