Ruby: opening files relative to home directory

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2010-03-24T00:39:53Z Indexed on 2010/03/24 0:43 UTC
Read the original article Hit count: 342

Filed under:

In Ruby, the following fails with Errno::ENOENT: No such file or directory, even if the file exists:

open('~/some_file')

However, you can do this:

open(File.expand_path('~/some_file'))

Two questions:

  1. Why doesn't open process the tilde as pointing to the home directory?
  2. Is there a slicker way than using File.expand_path?

© Stack Overflow or respective owner

Related posts about ruby