Last active
March 21, 2021 01:48
-
-
Save shuuuuun/54a840836f54d7668c37b03fa7c965b3 to your computer and use it in GitHub Desktop.
rubyのFileまわりで忘れがちなやつメモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
puts "__FILE__: #{__FILE__}" | |
puts "__dir__: #{__dir__}" | |
puts "File.dirname(__FILE__): #{File.dirname(__FILE__)}" | |
puts "File.expand_path('.', __FILE__): #{File.expand_path('.', __FILE__)}" | |
puts "File.expand_path('.', __dir__): #{File.expand_path('.', __dir__)}" | |
# スクリプトが1階層下にある場合 | |
APP_ROOT = File.expand_path('..', __dir__) | |
puts "APP_ROOT: #{APP_ROOT}" | |
# ex. | |
# $ cd /path/to/project | |
# $ scripts/hoge.rb | |
# __FILE__: scripts/hoge.rb | |
# __dir__: /path/to/project/scripts | |
# File.dirname(__FILE__): scripts | |
# File.expand_path('.', __FILE__): /path/to/project/scripts/hoge.rb | |
# File.expand_path('.', __dir__): /path/to/project/scripts | |
# APP_ROOT: /path/to/project |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment