Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...