微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby – 从父目录加载文件

我正在使用 Ruby 1.8,我有调用的脚本,但它在父文件夹中.以下是结构:
maindir/
neededscript.rb
  subdir/
    subdir2/
      myscript.rb

我怎样才能从myscript.rb里面找到needscript.rb?

解决方法

在Ruby> = 1.9中,您可以使用 require_relative方法

require_relative complements the builtin method require by allowing you to load a file that is relative to the file containing the require_relative statement.

require_relative '../../neededscript.rb'

原文地址:https://www.jb51.cc/ruby/268830.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐