Gem::Specification.new do |spec|
spec.name = 'the-name-of-your-gem'
spec.version ='0.0.1'
# this is important - it specifies which files to include in the gem.
spec.files = Dir.glob("lib/**/*") + %w{History.txt Manifest.txt} +
Dir.glob("path/to/resources/**/*")
# If you have resources in other directories than 'lib'
spec.require_paths << 'path/to/resources'
# optional, but useful to your users
spec.summary = "A more longwinded description of your gem"
spec.author = 'Your Name'
spec.email = 'you@yourdomain.com'
spec.homepage = 'http://www.yourpage.com'
# you did document with RDoc, right?
spec.has_rdoc = true
# if you have any dependencies on other gems, list them thusly
spec.add_dependency('hpricot')
spec.add_dependency('log4r', '>= 1.0.5')
end
然后,
$LOAD_PATH.each { |dir| ... look for resources relative to dir ... }
2条答案
按热度按时间lrpiutwd1#
基本上有两种方法,
1)可以使用
__FILE__
在gem中加载与Ruby文件相关的资源:2)您可以将任意路径从Gem添加到
$LOAD_PATH
变量,然后遍历$LOAD_PATH
以查找资源,例如:然后,
lf5gs5x22#
下面是我使用Ruby 3.1.1所做的工作:
这甚至适用于
gem_name
中的代码。