How are $LOAD_PATH and $: different?

Posted by Benjamin Oakes on Stack Overflow See other posts from Stack Overflow or by Benjamin Oakes
Published on 2010-05-27T15:35:54Z Indexed on 2010/05/27 15:41 UTC
Read the original article Hit count: 162

Filed under:
|

I needed to know what was in my Ruby load path, so I did this:

$ ruby -e "puts $LOAD_PATH"

It didn't print anything out, which I didn't expect. So I tried this:

$ ruby -e "puts $:"
/usr/local/lib/site_ruby/1.8
/usr/local/lib/site_ruby/1.8/i486-linux
/usr/local/lib/site_ruby/1.8/i386-linux
/usr/local/lib/site_ruby
/usr/lib/ruby/vendor_ruby/1.8
/usr/lib/ruby/vendor_ruby/1.8/i486-linux
/usr/lib/ruby/vendor_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i486-linux
/usr/lib/ruby/1.8/i386-linux
.

Why does the second one give me the expected output and the first one doesn't? Shouldn't they be the same? I just tried it in irb, and I got the results I expected.

This is my Ruby version, in case it makes a difference:

$ ruby --version
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]

© Stack Overflow or respective owner

Related posts about ruby

Related posts about load-path