Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

ruby - How to reference a file from inside of a gem

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...