如何从 gem 内部引用文件 [英] How to reference a file from inside of a gem

查看:11
本文介绍了如何从 gem 内部引用文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 gem 中找到文件绝对路径的正确方法是什么?换句话说,假设我在 gem_install_path/mygem/lib/mygem.rb 中,并且我想要 gem_install_path/mygem/foo/ 的路径.获得它的正确方法是什么?

What's the correct way to find the absolute path to a file from within a gem? In other words, let's say I'm in gem_install_path/mygem/lib/mygem.rb, and I want the path to gem_install_path/mygem/foo/. What's the correct way to get that?

推荐答案

不清楚你想要哪条路径,但可能以下其中一种方式会给你你想要的:

It is not clear which path you want, but probably one of the following will give you what you want:

Gem.loaded_specs["mygem"].base_dir
Gem.loaded_specs["mygem"].full_gem_path
Gem.loaded_specs["mygem"].gem_dir
Gem.loaded_specs["mygem"].gems_dir

这篇关于如何从 gem 内部引用文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆