Ben G. wrote in post #1119568:
>>
>> File.open(city_name, 'w') |w|
>>   for i in start_number...end_number
>>     w.puts i
>>   end
>> end
>>
>> File.open(city_name, 'w') |w|
>>   (start_number...end_number).each do |i|
>>     w.puts i
>>   end
>> end
>
> Robert, clever idea, I hadn't thought about it that way but I believe
> you forgot "do" before |w| :)

Right!  Well spotted.

> The reason I am using an array is that sometimes I will need to generate
> a secondary file, based off of the same numbers. In the second file I
> will need to iterate over the array and concatenate additional numbers
> onto the front of each value within the array.

What do you mean by "concatenate additional numbers onto the front of 
each value within the array"?  Do you mean prepend to the string 
representation?

> Sometimes that number begins with a 0, so I collect start_code with
>
> start_code = gets.to_s

".to_s" is superfluous.  I'd rather do

start_code = Integer(gets)

> then as the number list consists of integers I also have to convert that
> so I can concatenate the the values together. So I wrote this but this
> only generates an identical file with the altered file name. It seems as
> if start_code isn't being concatenated? I have tried several variations
> and different combinations in and out of block form.
>
>   File.open(city_name + start_code, 'w' ) do |w|
>   w.write((numberlist.each { |p|start_code << p.to_s }).join("\n") )

You are modifying start_code all the time here (if it is a String; if it 
is an integer value you create a shifted int value that is immediately 
lost.  Since you do not modify numberlist and values contained in it you 
do see exactly the same output as before.

You rather want something like

File.open(city_name + start_code, 'w' ) do |w|
  puts numberlist.map {|i| "#{start_code}#{i}"}
end

Kind regards

robert

-- 
Posted via http://www.ruby-forum.com/.