How are $LOAD_PATH and $: different?
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/li开发者_运维技巧b/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]
They are not. Try running this command:
$ ruby -e 'puts $LOAD_PATH'
which doesn't make shell expand $LOAD_PATH
due to use of '
instead of "
.
精彩评论