# Ruby gem newbie question

**URL:** <https://www.ruby-forum.com/t/ruby-gem-newbie-question/137789>\
**Category:** Ruby\
**Created:** [May 16, 2008, 12:27pm UTC](https://www.ruby-forum.com/t/ruby-gem-newbie-question/137789 "2008-05-16T12:27:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [May 16, 2008, 12:27pm UTC](https://www.ruby-forum.com/t/ruby-gem-newbie-question/137789/1 "2008-05-16T12:27:29Z")

</div>

Hi,

I am trying to create a ruby gem and I have a slight problem finding a  
file within it.

The structure of the code in my gem is as follows:

./  
bin/  
ai  
lib/  
app.rb  
app/  
# src files  
templates/  
default.txt  
.etc.

The gem loads fine, my problem is that I cannot find the default.txt  
file in the templates dir from within the code in the app dir when it is  
used from the command line.

I think it is trying to find the file in the working directory, but it  
is inside the gem. I have a line in my src file:

DEFAULT = “…/templates/default.txt”

What should I put in order to point to the file within the gem?

Thanks.

David.

---

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [May 16, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/ruby-gem-newbie-question/137789/2 "2008-05-16T13:45:25Z")

</div>

Ok, I found a fix. I am not sure if this is the correct way but it seems  
to work.

TEMPLATE\_DIR = “/…/templates/”  
DEFAULT = “default.txt”

template = File.dirname( **FILE** ) + TEMPLATE\_DIR + DEFAULT
