我使用Bundler爲我生成一個Gem骨架。在lib/foo.rb
,我有以下幾點:在RubyGem中需要文件的正確方法?
require 'foo/client'
require 'foo/other'
這兩行應該需要分別lib/foo/client.rb
和lib/foo/other.rb
。它的構建沒有問題,但是當我用irb
進行測試時,出現文件未找到錯誤。
ruby-1.9.2-head :003 > require 'foo'
LoadError: no such file to load -- foo/client
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/ethan/.rvm/gems/ruby-1.9.2-head/gems/foo-0.1.0/lib/foo.rb:3:in `<top (required)>'
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /home/ethan/.rvm/rubies/ruby-1.9.2-head/bin/irb:16:in `<main>'
ruby-1.9.2-head :004 >
在同一個Gem中需要文件的正確方法是什麼?必須有一些簡單的東西我正在監督...
使用require_relative,我仍然收到錯誤。 https://gist.github.com/1288893 –