matthiash
matthiash

Reputation: 3235

How does ruby find gems?

I have installed a gem called CSApi. ruby -e 'require "CSApi"' runs fine. gem env shows that /Library/Ruby/Gems/2.0.0 is on my GEM PATH, and there is a file /Library/Ruby/Gems/2.0.0/gems/CSApi-0.0.5/lib/csapi.rb I assume this is the file being loaded when i require CSApi.

Main question: How does ruby find this file? Is the whole directory structure under /Library/Ruby/Gems/2.0.0 traversed to find a file called csapi.rb?

Side question: There is also a file /Library/Ruby/Gems/2.0.0/gems/CSApi-0.0.5/examples/example.rb that was installed as part of the gem. Can this ruby script be invoked without typing the full path?

Upvotes: 3

Views: 390

Answers (1)

errata
errata

Reputation: 26812

You can see the paths require traverses by typing

ruby -e 'puts $:'

Ok, sorry that was incomplete, this should show the gem paths:

ruby -r rubygems -e "p Gem.path"

Upvotes: 1

Related Questions