George
12/19/2006 6:34:00 AM
On 12/19/06, Josselin <josselin@wanadoo.fr> wrote:
> I wrote that the newbie way, but is there any way to DRY it ?
>
> closed_cities = []
> 0.step(9, 1) do |i|
> closed_cities << City.find_by_id( city_25 [i] [0] )
> i = i.next
> end
>
> if yes, is it only for fun , or does it impact performance (a lot ?)
Not sure where the "wet" bit is, but the "i = i.next" is redundant, as
'i' gets assigned on each call of the block.
Without knowing more about what each thing is/does, I'd recommend:
closed_cities = (0..9).map{|i| City.find_by_id(city_25[i][0])}
> thanks for your lights
Welcome!