title: Assign different variable names (which are nil array) through a loop
body: <p>I have a loop which should assign different variable names depending on filesname which are contained in an array.</p>
  
  <p>Each variable is set as an empty array.</p>
  
  <pre><code>filenames = ['file1', 'file2']
  
  filenames.each do |filename|
    "@data_" + "#{filename}" = []        # used @ as I need these variables externaly from the loop
  end
  </code></pre>
  
  <p>This gives me the following error </p>
  
  <pre><code>syntax error, unexpected '=', expecting keyword_end
  </code></pre>
  
  <p>What I don't understand is if I use</p>
  
  <pre><code>filenames.each do |filename|
    p "@data_" + "#{filename}"
  end
  </code></pre>
  
  <p>it renders correctly </p>
  
  <pre><code>@data_file1
  @data_file2
  </code></pre>
  
  <p>And if I set an empty array through the loop</p>
  
  <pre><code>filenames.each do |filename|
    @data = []
  end
  p @data
  #=&gt; []
  </code></pre>
  
  <p>it works too...</p>
  
  <p>Thanks for your help!</p>