title: Opening file from directory in ruby using File.open
body: <p>I am relatively new to Ruby, I am trying to open a file in a way like:  </p>
  
  <pre><code>#! /usr/bin/env ruby
  data_file = '~/path/to/file.txt'
  file = File.open(data_file, 'r')
  </code></pre>
  
  <p>however I get "No such file or directory" (the file does exist in that directory).  It works if I put that path to the file as a command line argument such as:</p>
  
  <pre><code>#! /usr/bin/env ruby
  file = File.open(ARGV[0], 'r')
  </code></pre>
  
  <p>and then run from the command line like: ruby script.cgi ~/path/to/file.txt</p>
  
  <p>Any ideas how to get it to work the first way?</p>