title: How do I open each file in a directory with Ruby?
body: <p>I need to open each file inside a directory. My attempt at this looks like:</p>
  
  <pre><code>Dir.foreach('path/to/directory') do |filename|
    next if filename == '.' || filename == '..'
    puts "working on #{filename}"
  
    # this is where it crashes
    file = File.open(filename, 'r')
  
    #some code
  
    file.close
  
    # more code
  
  end
  </code></pre>
  
  <p>My code keeps crashing at <code>File.open(filename, 'r')</code>. I'm not sure what <code>filename</code> should be.</p>