Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Created May 21, 2009 12:53
Show Gist options
  • Save pokutuna/115443 to your computer and use it in GitHub Desktop.
Save pokutuna/115443 to your computer and use it in GitHub Desktop.
class File
def self.actual_path(file = nil)
file = __FILE__ if file == nil
file = File.expand_path(file)
if File.ftype(file) == 'link' then
actpath = File.readlink(file)
file = File.actual_path(actpath)
end
return file
end
end
if $0 == __FILE__ then
p __FILE__
p File.expand_path(__FILE__)
p File.actual_path(__FILE__)
end
$ cd ~/
$ mkdir slinktest
$ cd slinktest
$ mkdir hoge
$ cd hoge
$ cp ~/filepath.rb ./
$ cd ..
$ ln -s hoge/filepath.rb ./filepath_slink.rb
$ ls -l
合計 4
lrwxrwxrwx 1 pokutuna pokutuna 16 2009-05-21 21:46 filepath_slink.rb -> hoge/filepath.rb
drwxr-xr-x 2 pokutuna pokutuna 4096 2009-05-21 21:43 hoge
$ ruby filepath_slink.rb
"filepath_slink.rb"
"/home/pokutuna/slinktest/filepath_slink.rb"
"/home/pokutuna/slinktest/hoge/filepath.rb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment