Ruby gem newbie question

Discussion in 'Ruby' started by David Madden, May 16, 2008.

  1. David Madden

    David Madden Guest

    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.
    --
    Posted via http://www.ruby-forum.com/.
    David Madden, May 16, 2008
    #1
    1. Advertising

  2. David Madden

    David Madden Guest

    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

    --
    Posted via http://www.ruby-forum.com/.
    David Madden, May 16, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gga
    Replies:
    0
    Views:
    130
  2. han
    Replies:
    1
    Views:
    120
    Lyle Johnson
    Oct 24, 2005
  3. Ara.T.Howard
    Replies:
    0
    Views:
    165
    Ara.T.Howard
    Oct 27, 2005
  4. Austin 7873
    Replies:
    5
    Views:
    182
    Eric Hodel
    Jan 27, 2007
  5. Iñaki Baz Castillo
    Replies:
    1
    Views:
    152
    Iñaki Baz Castillo
    Feb 28, 2011
Loading...

Share This Page