On Apr 28, 2011, at 12:07 AM, Jesù¸ Gabriel y GaláÏ wrote:

> On Wed, Apr 27, 2011 at 5:56 PM, Zhi-Qiang Lei <zhiqiang.lei / gmail.com> wrote:
>> Hi,
>> 
>> I'm trying to package a library into a gem. I write the main file with autoload, just like Rack's.
>> 
>> module RenrenAPI
>> 
>>  autoload :Authentication, "renren_api/authentication"
>>  autoload :SignatureCalculator, "renren_api/signature_calculator"
>>  autoload :HTTPAdapter, "renren_api/http_adapter"
>> 
>> end
>> 
>> But when I use the gem, I get a LoadError.
>> 
>>> RenrenAPI::Authentication
>> LoadError: no such file to load -- renren_api/authentication
>> 
>> The file does exist. Does anyone can tell me what the problem is with my library, which does not happen to Rack.
> 
> You can check the load path:
> 
> p $:
> 
> before your code to check where Ruby is looking for requires. BTW,
> Ruby 1.9 removed "." from the load path.
> 
> Jesus.
> 


It shows that the lib directory is in the load path. (/Users/siegfried/.rvm/gems/ruby-1.9.2-head/gems/renren-api-0.3.1/lib)

bogon% irb
ruby-1.9.2-head :001 > require "renren_api"
 => true 
ruby-1.9.2-head :002 > RenrenAPI::Authentication
LoadError: no such file to load -- renren_api/authentication
	from (irb):2
	from /Users/siegfried/.rvm/rubies/ruby-1.9.2-head/bin/irb:16:in `<main>'
ruby-1.9.2-head :003 > p $:
["/Users/siegfried/.rvm/gems/ruby-1.9.2-head/gems/renren-api-0.3.1/lib", "/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1", "/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0", "/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby", "/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/vendor_ruby/1.9.1",/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin10.6.0", "/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/vendor_ruby", "/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1", "/Users/siegfried/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/x86_64-darwin10.6.0"]

The directory structure is:

|~lib/
| |~renren_api/
| | |-authentication.rb
| | |-http_adapter.rb
| | `-signature_calculator.rb
| `-renren_api.rb

The code I mentioned is the content of lib/renren_api.rb

Best regards,
Zhi-Qiang Lei
zhiqiang.lei / gmail.com