Question

I am trying to structure my ruby project following best practices. I currently have something like this:

test_project/
   bin/
       test_project # My Executable
   lib/
       test_project/
           my_module.rb
       test_project.rb # Loads my_module.rb

I setup it up this way based on recommendations I found on the web.

My problem is I have some resource files, "resouce1.txt" and "resouce2.txt". My executable needs to open the file "resource1.txt". my_module.rb needs to be able to open the file "resource2.txt". Where do I put these plan text resource files in this directory structure and how to I open them (File.open) from the corresponding ruby files.

Thanks in advanced,
Corsen

Was it helpful?

Solution

Since /lib has to do with specifically the Ruby that powers your gems, I would put it in a top-level directory in your gem named after their subject matter. If they are files with lists of species I would call it /species.

You could also go the Rails way and put it in an /assets folder if you have a lot of external assets like /assets/species. Either way, I would not be prone to put them in /lib.

OTHER TIPS

I don't think there is a standard place for these, as for the most part it is operating system dependent (/var and /etc vs Program Files vs the Application Bundle). But your best bet (I think) is to either put them in the root of your hierarchy, put them in lib/ or, if they really are static text files, put them in your script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top