__FILE__
사용하여 당신은 당신의 보석에 루비 파일에 상대적으로 자원을로드 할 수 있습니다
1) 두 가지 방법으로, 기본적으로 :
def path_to_resources
File.join(File.dirname(File.expand_path(__FILE__)), '../path/to/resources')
end
2) 당신은 당신의 보석에서 임의의 경로를 추가 할 수는 $LOAD_PATH
, 예를 들어, 변수 다음 자원을 찾기 위해 $LOAD_PATH
도보
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 = '[email protected]'
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 ... }
처음에는 매력처럼 작동했습니다. :) – Drew
올바른 경로를 찾으려면 Gem.data_dir을 사용하십시오. – ch2500