From: Timothy Hunter Date: 2006-02-13T07:03:26+09:00 Subject: Re: newbie question about blocks Jeppe Jakobsen wrote: > Hi, I want to square every element in my array using a block: > > a = (1..1000).to_a > a.each {|x| x**2} > > But this does not seem to work, it just outputs my array completely > unchanged :( > > -- > "winners never quit, quitters never win" > The collect method will produce a new array: a.collect {|x| x*x} or, if you want to modify the original array, use collect!