How to Organize a New Ruby Project

By Christopher Haupt

Before each project in Ruby, you’ll want to get organized by keeping all your work for the project together in an easy-to-find place. You’ll repeat these steps for each new project, so now is a good time to get comfortable using the combination of your terminal program and your code editor.

When working on more complex projects in Ruby, you’ll be using Atom, the programmer’s editor, to write and store code in files. You’ll continue to use the terminal program to use a different Ruby command to run and test the code stored in the files you create.

The nice thing about Interactive Ruby (IRB) is that you can get a feel for what the code is going to do immediately. This works great for small snippets of Ruby, but as you start to create more complicated programs, and as they get longer, IRB isn’t very forgiving if you make typos or want to easily change or save your work.

If you haven’t created a development folder already, you should create one first and then follow these steps to create a folder for your new project (called Project 04 in this example):

  1. Start your terminal program and enter the development folder:

    $ cd development
  2. Create a new directory for this project:

    $ mkdir project04
  3. Move in to the new directory:

    $ cd project04
  4. Start Atom by double-clicking its icon.

    When Atom starts for the first time, it displays the Welcome tab and the Welcome Guide tab. You won’t need these tabs during this project.

  5. Click the Welcome Guide tab and choose File→Close Tab to close the Welcome Guide tab. Repeat the process for the Welcome tab.

    Close the Welcome Guide tab.
    Close the Welcome Guide tab.
  6. If you don’t have one tab remaining called Untitled, choose File→New File to get a new file started.

    Use the New File menu option to create an empty Ruby file.
    Use the New File menu option to create an empty Ruby file.
  7. Even before you’ve written any code, save the file one time to make sure that it gets placed in the proper folder.

    To do that, choose File→Save. A standard Save dialog box appears. Navigate to your development folder in your home directory and then choose the project04 folder. Name your file shapes.rb and click Save.

    Use the Save dialog box to save your work.
    Use the Save dialog box to save your work.
  8. Switch over to your terminal program and list out the files in the project04 folder. On Mac, the command is:

    $ ls

    On Windows, the command is:

    C:Userschrisdevelopmentproject04> dir

    Your prompt on Mac or Windows may look a little different than mine. That doesn’t matter as long as you type the command correctly!

    You should see shapes.rb. If not, make sure that you saved the file in the correct folder. Go back to Atom, choose File→Save As, and navigate to the correct folder.

Now you’re ready to write some code!