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 <[email protected]> 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/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to