title: Ruby Meaningful Words -- Remove Stopwords
body: <p>I have an array of speech files, and I need to compare to an array of stopwords to remove the stopwords and leave the remaining meaningful words.</p>
  
  <p>So far I have something like this:</p>
  
  <pre><code>stopwords = File.readlines('PATH TO TXT FILE')
  speeches = []
  
  Dir.glob('PATH TO ALL SPEECHES').each do |speech|
      #code to read each speech and store into an array
      f = File.readlines(speech)
      speeches &lt;&lt; f
  end
  
  lincolnSpeech = speeches[0]
  
  def process_file(file_name)
      all_words = file_name.scan(/\w+/)
      meaningful_words = all_words.select { |word| !stopwords.include?(word) }
      return meaningful_words
  end
  </code></pre>
  
  <p>I'm embedding the result of this function into my HTML, like so:</p>
  
  <pre><code>&lt;ul&gt;
        &lt;li&gt;&lt;pre style="white-space: pre-wrap;word-wrap: break-word"&gt;#{process_file(lincolnSpeech)}&lt;/pre&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>But this breaks the page and causes my HTML to disappear entirely. I've narrowed the problem down to the line in the function:</p>
  
  <pre><code>meaningful_words = all_words.select { |word| !stopwords.include?(word) }
  </code></pre>
  
  <p>And this line is the culprit. I'm not sure why it breaks my code. Maybe parts of this are deprecated? Can anyone offer some ideas about why this doesn't work, and perhaps alternate ways to achieve the effect I'm going for?</p>