I have a Ruby script that is trying to require a restclient module. When I reduce it to one line, it still fails:
#!/usr/bin/env ruby require 'restclient'
When I run it, I get the following error:
./test.rb:3:in `require': no such file to load -- restclient (LoadError) from ./test2.rb:3
When I run irb, the module loads normally:
$ irb >> require "restclient" => true >>
As far as I can tell, it looks like both script and irb have the same module paths:
$ ruby -e "puts $:" /Library/Ruby/Site/1.8 /Library/Ruby/Site/1.8/powerpc-darwin10.0 /Library/Ruby/Site/1.8/universal-darwin10.0 /Library/Ruby/Site /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8/universal-darwin10.0 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin10.0 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 . $ irb >> puts $: /Library/Ruby/Site/1.8 /Library/Ruby/Site/1.8/powerpc-darwin10.0 /Library/Ruby/Site/1.8/universal-darwin10.0 /Library/Ruby/Site /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8/universal-darwin10.0 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin10.0 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 . => nil >>
What can cause module loading through irb, but not when starting through Ruby?
Another confusing detail is that the restclient gem doesn't seem to be on my way to get started. How does irb find this?
$ locate restclient | grep gems /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/bin/restclient /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/abstract_response.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/exceptions.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/net_http_ext.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/payload.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/raw_response.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/resource.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/response.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient.rb /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/spec/restclient_spec.rb
Thanks - Mark
source share