How to find the path a Ruby Gem is installed at (i.e. Gem.lib_path c.f. Gem.bin_path)

前端 未结 4 1965
灰色年华
灰色年华 2020-12-24 01:24
Gem.bin_path(\'cucumber\', \'cucumber\')

Will return the binary/executable\'s path. It seems there is no such function to return the library path.

4条回答
  •  独厮守ぢ
    2020-12-24 01:33

    After the gem has been loaded with require, you find the lib path using Gem.loaded_specs as follows:

    require 'rubygems'
    require 'cucumber'
    gem_root = Gem.loaded_specs['cucumber'].full_gem_path
    gem_lib = File.join(gem_root, 'lib')
    

提交回复
热议问题