一个Ruby脚本可以告诉它什么目录? [英] Can a Ruby script tell what directory it’s in?
本文介绍了一个Ruby脚本可以告诉它什么目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
灵感来自获取源目录的一个Bash脚本从,什么是Ruby的方式来做到这一点?
Inspired by "Getting the source directory of a Bash script from within", what's the Ruby way to do this?
推荐答案
File.dirname(__ FILE __)
将为您提供相对于正在运行的脚本的路径。
File.expand_path(File.dirname(__ FILE __))
将为您提供绝对路径。
File.dirname(__FILE__)
will give you the path relative to the script being run.
File.expand_path(File.dirname(__FILE__))
will give you the absolute path.
这篇关于一个Ruby脚本可以告诉它什么目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文