ruby - why can I require gems which are outside from $LOAD_PATH -


i installed gem coffee-cup in rvm gem set,ruby-2.1.1@test path /users/dingxijin/.rvm/gems/ruby-2.1.1@test/gems/coffee-cup-0.0.4.

then open irb,just this:

2.1.1 :001 > puts $: /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/site_ruby/2.1.0 /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/site_ruby/2.1.0/x86_64-darwin12.0 /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/site_ruby /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/vendor_ruby/2.1.0 /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/vendor_ruby/2.1.0/x86_64-darwin12.0 /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/vendor_ruby /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0 /users/dingxijin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/x86_64-darwin12.0  => nil 2.1.1 :002 > require "coffee-cup" nameerror: uninitialized constant coffeecup::rails     /users/dingxijin/.rvm/gems/ruby-2.1.1@test/gems/coffee-cup-0.0.4/lib/coffee-cup/engine.rb:2:in `<module:coffeecup>' .......... 

does ruby search gems $load_path directories? why can require coffee-cup,it's $load_path doesn't have directory?

the original, “normal” behaviour of require how have described it: load_path searched requested file , if it’s not found load_error raised. rubygems modifies behaviour replacing kernel#require method. comment new require method explains happens:

when rubygems required, kernel#require replaced our own capable of loading gems on demand.

when call require 'x', happens:

  • if file can loaded existing ruby loadpath, is.
  • otherwise, installed gems searched file matches. if it's found in gem 'y', gem activated (added loadpath).

the normal require functionality of returning false if file has been loaded preserved.

with rubygems included in ruby default, new behaviour norm.

in example if @ load path again after have required file gem should see gems’ path has been added.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -