title: Loop through array, convert strings to array, push to new array in Ruby
body: <p>I'm currently working on a project where I need to loop through an array of strings, convert those strings into arrays, and push those arrays into a larger array. Some of the strings have word duplication, so I need to remove that as well. I want to avoid hard-coding everything, so I'm trying to write as many functions as I can.</p>
  
  <p>Here's an example of what I'm talking about.</p>
  
  <pre><code>old_array = ['Lilies are lovely lovely', 'Roses are romantic romantic', 'Daisies are bright bright']
  
  new_array = []
  </code></pre>
  
  <p>Here's what the new array should look like:</p>
  
  <pre><code>new_array = [['Lilies', 'are', 'lovely'], ['Roses', 'are', 'romantic'], ['Daisies', 'are', 'bright']]
  </code></pre>
  
  <p>So the strings from old_array must be transformed into sub-arrays, with duplicate words removed.</p>
  
  <p>I've been trying this and variations for a while, and it's not working very well.</p>
  
  <pre><code>def s_to_a(array)
    array.each do |string|
      string.split(" ").uniq
      new_array.push(string) #pretty sure this is incorrect
    end
  end
  
  s_to_a(old_array)
  </code></pre>
  
  <p>The error I keep getting is that new_array is an undefined local variable because I initialized it outside the function. Am I going about this the wrong way? Anyone have any pointers?</p>