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: 363
ruby
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:
- Why doesn't
open
process the tilde as pointing to the home directory? - Is there a slicker way than using
File.expand_path
?
© Stack Overflow or respective owner