chen li a ?crit :
> Hi all,
> 
> I want to create an array as following:
> a4=['name 1','name 2'...'name 20'].
> 
> It looks like a range for me. But I can't find a
> method in class Range to create this array. Here is my
> script I am not sure if this the Ruby way to do this.
> Any inputs?
> 
> Li
> 
> #
>  str='name 1'  
>   a4=[]
>  1.upto(20) do|i|
>  a4 <<(str.split()[0]+" #{i}")       
>  end
> 
> p a4
> #output
> ["name 1", "name 2", "name 3", "name 4", "name 5",
> "name 6", "name 7", "name 8", "name 9", "name 10",
> "name 11", "name 12", "name 13", "name 14", "name 15",
> "name 16", "name 17", "name 18", "name 19", "name 20"]
>> Exit code: 0

I will do it like this :

$ irb
 >> (1..20).map { |i| "name #{i}" }
=> ["name 1", "name 2", "name 3", "name 4", "name 5", "name 6", "name 
7", "name 8", "name 9", "name 10", "name 11", "name 12", "name 13", 
"name 14", "name 15", "name 16", "name 17", "name 18", "name 19", "name 20"]

-- 
Bruno Michel