Alex Rivera | Logout

Directory layout for pure Ruby project

Asked 2008-09-11T11:58:06.000
23

I'm starting to learn ruby. I'm also a day-to-day C++ dev. For C++ projects I usually go with following dir structure

/
 -/bin <- built binaries
 -/build <- build time temporary object (eg. .obj, cmake intermediates)
 -/doc <- manuals and/or Doxygen docs
 -/src
 --/module-1
 --/module-2
 -- non module specific sources, like main.cpp
 - IDE project files (.sln), etc.

What dir layout for Ruby (non-Rails, non-Merb) would you suggest to keep it clean, simple and maintainable?

Edit
Report

1 Answer

13

The core structure of a standard Ruby project is basically:

  lib/
    foo.rb
    foo/
  share/
    foo/
  test/
    helper.rb
    test_foo.rb
  HISTORY.md (or CHANGELOG.md)
  LICENSE.txt
  README.md
  foo.gemspec

The share/ is rare and is sometimes called data/ instead. It is for general purpose non-ruby files. Most projects don't need it, but even when they do many times everything is just kept in lib/, though that is probably not best practice.

The test/ directory might be called spec/ if BDD is being used instead of TDD, though you might also see features/ if Cucumber is used, or demo/ if QED is used.

These days foo.gemspec can just be .gemspec --especially if it is not manually maintained.

If your project has command line executables, then add:

  bin/
    foo
  man/
    foo.1
    foo.1.md or foo.1.ronn

In addition, most Ruby project's have:

  Gemfile
  Rakefile

The Gemfile is for using Bundler, and the Rakefile is for Rake build tool. But there are other options if you would like to use different tools.

A few other not-so-uncommon files:

  VERSION
  MANIFEST

The VERSION file just contains the current version number. And the MANIFEST (or Manifest.txt) contains a list of files to be included in the project's package file(s) (e.g. gem package).

What else you might see, but usage is sporadic:

  config/
  doc/ (or docs/)
  script/
  log/
  pkg/
  task/ (or tasks/)
  vendor/
  web/ (or site/)

Where config/ contains various configuration files; doc/ contains either generated documentation, e.g. RDoc, or sometimes manually maintained documentation; s

answered 2012-12-24T09:23:29.497

Your Answer