title: Opening a Text File in Ruby
body: <p>I am trying to create a program that will count the word frequency within a text file that I have created. I have a text file titled <code>moms_letter.txt</code> and this is my code:</p>
  
  <pre><code>word_count = {}
  
  File.open("moms_letter.txt", "r") do |f|
      f.each_line do |line|
          words = line.split(' ').each do |word|
              word_count[word] += 1 if word_count.has_key? word
              word_count[word] = 1 if not word_count.has_key? word
          end
      end
  end
  
  puts word_count
  </code></pre>
  
  <p>The problem I am getting is when I go to run the file, I get the error:</p>
  
  <pre><code>there is no such file or directory - moms_letter.txt (Errno: : ENOENT)
  </code></pre>
  
  <p>Not quite sure why this is occurring when I have the text file created. 
  Any help is appreciated. </p>
  
  <p>I am also newbie in Ruby, so thanks for the patience. </p>