LoginSignup
18
11

More than 5 years have passed since last update.

Ruby で現在実行しているスクリプトのディレクトリパスを取得する

Posted at

__dir__ を使うことで取得できます。(2.0 から使用出来ます)

p __dir__

__FILE__File.expand_path を組み合わせたパターンを見かけますが __dir__ のほうがより簡潔に書けます。

# 結果は一緒
p File.expand_path("..", __FILE__)
p __dir__

参考サイト

18
11
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
11