Guys,
I’m getting confused by requiring and the loadpath array.
By my understanding,
- $LOAD_PATH is an array for locations where ruby interpretor will
search for files to load/require. - Requiring or loading a thing by (require “arel” or load “arel”),
means we are actually running the file arel.rb, found somewhere in our
$LOAD_PATH locations.
Let me explain my doubt with some irb session code.
ruby-1.9.2-p180 :001 > puts $:
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin10.6.0
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/x86_64-darwin10.6.0
=> nil
ruby-1.9.2-p180 :002 > require ‘cgi’
=> true
ruby-1.9.2-p180 :003 > puts $:
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin10.6.0
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/x86_64-darwin10.6.0
=> nil
ruby-1.9.2-p180 :004 > require ‘arel’
=> true
ruby-1.9.2-p180 :005 > puts $:
/Users/lakshman/.rvm/gems/ruby-1.9.2-p180/gems/arel-2.0.9/lib
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/x86_64-darwin10.6.0
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin10.6.0
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/vendor_ruby
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1
/Users/lakshman/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/x86_64-darwin10.6.0
=> nil
cgi is in ruby standard library. For require “cgi”, cgi.rb is in
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1 and it didnt give any error
while requiring it.
arel is a gem. arel.rb is found in
~/.rvm/gems/ruby-1.9.2-p180/gems/arel-2.0.9/lib. This location was not
there in the $: and the call for require ‘arel’ didn’t throw an error.
The location was added AFTER I requried it.
whats happening for these ruby gems. can you explain how this require
and new-path-additions-to-load-path works…