FILE ã¯ããã®ã¾ã¾ã ã¨ã¢ãã«ãªããªãã
ruby ã® ruby-doc ã«ã¯ãã®ããã«æ¸ãã¦ããã
FILE
ç¾å¨ã®ã½ã¼ã¹ãã¡ã¤ã«å
ãã«ãã¹ã¨ã¯éããªãããããã«ãã¹ãå¿ è¦ãªå ´å㯠File.expand_path( FILE) ã¨ããå¿ è¦ãããã¾ãã
ãã«ãã¹ã¨ã¯éããªãã¨ããããã·ã³ããªãã¯ãªã³ã¯ã§ãå ãã¡ã¤ã«ã«ã¯ãªããªããã½ã¼ã¹ãã¡ã¤ã«åã¨ããããããå®è¡ä¸ã®ãã¡ã¤ã«åãã§ããã
ãã¨ãã°ããªã³ã¯ãä½ã£ã¦ã¿ãã
ln -s sample.rb ~/linked.rb
sample.rb ã linked.rb ã«ãã¦ããªã³ã¯ããå ´åã® FILE ãã©ããªãã調ã¹ã¦ã¿ããã¨ã«ãããã»ã»ã»
~/Desktop/sample.rb
__FILE__: sample.rb $0 : sample.rb File.expand_path($0): /Users/takuya/Desktop/sample.rb File.realpath($0) : /Users/takuya/Desktop/sample.rb File.expand_path(__FILE__): /Users/takuya/Desktop/sample.rb File.realpath(__FILE__) : /Users/takuya/Desktop/sample.rb
~/linked.rb
__FILE__: /Users/takuya/linked.rb $0 : /Users/takuya/linked.rb File.expand_path($0):/Users/takuya/linked.rb # ããã¯ã»ã»ã» File.realpath($0) : /Users/takuya/Desktop/sample.rb File.expand_path(__FILE__): /Users/takuya/linked.rb # ã㣠File.realpath(__FILE__) :/Users/takuya/Desktop/sample.rb
FILE ã¯å®è¡ä¸ã®ãã¡ã¤ã«
ãªã³ã¯ãããã¢ã¬ã³ã¬ã FILE ã¯ãã¾ã®Pathãªãã ãããã©ãrequire ãããã©ããªããã ãã
Pathãå¿ è¦ãªãrealpath ããæ¹ãããã
$: / $LOAD_PATH ãããªã«ããã¡ã¤ã«ãèªã¿è¾¼ãã¨ãã«ãå®è¡ä¸ã®ãã¡ã¤ã«åããç¸å¯¾çã«ãã©ãã®ã§ããã°ãexpand_pathããã¾ãã«ãrealpathããªãã¨ãã°ãèµ·ãããããã