Just a little help, you''re thinking about loops to fill arrays, and
that is where you''re getting stuck. In ruby, most "loops" are
iterators/closures, so I think you could start thinking about
closures. For example, the Array.new expects a parameter and a block,
or two parameters. So, if you want an array with 10 values, and set
all values to "string", for example, you could use:
Array.new(10, "string")
Otherwise, if you want to populate the array based on the index of
each element, you could use the block version:
Array.new(26) { |index| index }
The block will "iterate", starting on index 0 and ending on index 25
(26 elements) and return the index value. If you wanted, for example,
an array with the square of 0 through 10 you could use:
Array.new(11) { |index| index * index }
In your example, like Tony said, you could convert a range to a array.
On Oct 6, 3:26 pm, First Bat
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> i am trying to use a loop to fill an array with numbers from 0 through
> 25, but i have no idea how to do it. Can someone please help? thank you
> --
> Posted viahttp://www.ruby-forum.com/.