Adding to the Ruby library path

Posted by admin, Sat Oct 20 04:40:23 UTC 2007

I couldn’t comment on David’s blog ( must be logged in… no way to log in provided :-( )

David Orriss Jr – The Delusion That People Care About What I Think » Blog Archive » How Ruby Finds Libraries

In Ruby not library management is not always as simple as running gem install. Some Ruby code is distributed simply as libraries. So where do you put these libraries? The clue is in the Ruby $LOAD_PATH variable.
<br /> irb(main):001:0&gt; puts $LOAD_PATH<br /> /usr/local/lib/ruby/site_ruby/1.8<br /> /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.10.1<br /> /usr/local/lib/ruby/site_ruby<br /> /usr/local/lib/ruby/1.8<br /> /usr/local/lib/ruby/1.8/i686-darwin8.10.1<br /> . =&gt; nil<br /> irb(main):002:0&gt; <br />
This tells you that you can put your library code in any of the above listed directories and if Ruby still can’t find the code it will try the current directory you’re running code in before giving up. Personally I end up using the /usr/local/lib/ruby/1.8 folder.


I just found this little gem yesterday:

<br />$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'<br />

Which, used in a Rakefile, will add the lib dir below the current directory to the load path.

Filed Under: | Tags:

Comments

  1. David O 10.21.07 / 14PM
    I better make it so you can create logins I guess.. ;)
  2. Heel 05.01.11 / 10AM
  3. Heel 05.01.11 / 10AM
  4. Heel 05.01.11 / 10AM
  5. Heel 05.01.11 / 10AM
  6. Heel 05.01.11 / 10AM
  7. Arnie 05.01.11 / 10AM
  8. Arnie 05.01.11 / 10AM
  9. Arnie 05.01.11 / 10AM
  10. Arnie 05.01.11 / 10AM
  11. Arnie 05.01.11 / 10AM
  12. Diesel 05.01.11 / 10AM
  13. Diesel 05.01.11 / 10AM
  14. Diesel 05.01.11 / 10AM
  15. Diesel 05.01.11 / 10AM
  16. Diesel 05.01.11 / 10AM
  17. Neo 05.01.11 / 10AM
  18. Neo 05.01.11 / 10AM
  19. Neo 05.01.11 / 10AM
  20. Neo 05.01.11 / 10AM
  21. Neo 05.01.11 / 10AM
  22. Hero 05.01.11 / 10AM
  23. Hero 05.01.11 / 10AM
  24. Hero 05.01.11 / 10AM
  25. Hero 05.01.11 / 10AM
  26. Hero 05.01.11 / 10AM
  27. Hero 05.01.11 / 10AM
  28. Hero 05.01.11 / 10AM
  29. Hero 05.01.11 / 10AM
  30. Hero 05.01.11 / 10AM
  31. Hero 05.01.11 / 10AM
  32. Arnie 05.01.11 / 10AM
  33. Arnie 05.01.11 / 10AM
  34. Arnie 05.01.11 / 10AM
  35. Arnie 05.01.11 / 10AM
  36. Arnie 05.01.11 / 10AM
  37. Heel 05.01.11 / 10AM
  38. Heel 05.01.11 / 10AM
  39. Heel 05.01.11 / 10AM
  40. Heel 05.01.11 / 10AM
  41. Heel 05.01.11 / 10AM

Have your say

A name is required. You may use HTML in your comments.