Expanding tildes in filenames

Hi all,

Just curious if there’s a Ruby idiom out there for automatic tilde expansion
in filenames. Perl does it like this (taken from the Perl Cookbook, p.

$filename =~ s/{ ^ ~ ( [^/]* ) }
{ $1
? (getpwnam($1))[7]
: ( $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($>))[7])

Will I have to do something similar for Ruby?

How do people feel about adding automatic tilde expansion into the IO class?
In other words, you would be able to do:

IO.foreach("~/djberge/.vimrc"){ |line|
puts line

and it would automatically expand that to your home dir and read your .vimrc
file (for example).

Comments? Suggestions?



IO.foreach("~/djberge/.vimrc"){ |line|

   IO.foreach(File::expand_path("~/djberge/.vimrc")) { |line|

   puts line

Guy Decoux