On Aug 20, 2006, at 12:26 AM, Andy Black wrote:

> Hi list,
>
> I need to create a different array each time that I am going through a
> loop.
> I wonder how I can assign different names to the arrays based on the
> iteration count.
> For example first time that I go through the loop I want to create an
> array named: a1, second one, a2 and so on.
> Thanks a lot for your help.

By far the easiest way to do this is to stick them in a hash:

hash = {}
10.times do |count|
     hash["a" + count.to_s] = [....]
end

This is, um, very similar to an array, except with "a<count>" as the  
subscript instead of <count>.

If you absolutely must have a variable, then AFAIK you have to use an  
instance variable:

10.times do |count|
   instance_variable_set("@a#{count}", [...])
end

There might be a way to create a local variable, but even if you did  
it would go out of scope as soon as the block ended, so it would be  
pretty useless.

-- 
Luke Kanies
http://madstop.com | http://reductivelabs.com | 615-594-8199