How to get a file contained in a gem "lib" directory?

Hi, I’ve build a gem “mylib” which contains a file called “myfile.xml”
under
“lib/mylib” dir. Let’s imagine that depending on the environment it is
stored
(after installed) in:

/usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

But of course there could be different versions of the gem:

/usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.0/lib/mylib/myfile.xml
/usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

Then I write a program which does:

require “mylib”

so the latest version (1.0.1) is loaded.

How would I get “myfile.xml” for the loaded “mylib” gem version? I’m
looking
for a Gem class method like “Gem.bin_path(gemname)” but I cannot find
it.

Thanks a lot.

El Lunes, 21 de Diciembre de 2009, Iñaki Baz C. escribió:

Then I write a program which does:

require “mylib”

so the latest version (1.0.1) is loaded.

How would I get “myfile.xml” for the loaded “mylib” gem version? I’m
looking for a Gem class method like “Gem.bin_path(gemname)” but I cannot
find it.

Found it:
Gem.required_location(gemname,"")

Iñaki Baz C. wrote:

Hi, I’ve build a gem “mylib” which contains a file called “myfile.xml”
under
“lib/mylib” dir. Let’s imagine that depending on the environment it is
stored
(after installed) in:

/usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

[…]

How would I get “myfile.xml” for the loaded “mylib” gem version?

You can put a method to return it in your mylib.rb:

def self.get_xml_pathname
File.join(File.dirname(FILE), ‘mylib.xml’)
end