[LRUG] Working out the path of a gem from within the gem

Dan Webb dan at danwebb.net
Mon Mar 3 03:21:19 PST 2008


Hello all,

Having a problem that I can't successfully google and I wondered if
any of you had come across the problem before and have any wisdom.
Here goes...

I'm writing a gem where some of the code in the lib dir refers to a
yaml file in the data directory of the gem.  In the code I try to load
the yaml file like this:

YAML.load_file(File.join(File.dirname(__FILE__), '..', 'data',
'country_codes.yml'))

But, when you load the gem it turns out that __FILE__ is set to:

/Library/Ruby/Site/1.8/country_codes.rb

Instead of the actual file.  Which is annoying but hey, its all the
fun of ruby.  My question is though, how can I refer the installed gem
directory?

Cheers,

-- 
Dan Webb
http://www.danwebb.net

aim: danwrong123
skype: danwrong



More information about the Chat mailing list