Posts Tagged ‘Ruby and Eclipse’

By Mike Hubbartt, Copyright 2011, All Rights Reserved.

This brief tutorial is meant to help people get started writing their first Ruby program using the Eclipse IDE.

Step 1: See if Ruby is already installed.

Ruby does ship with some operating systems, however it is available for multiple operating systems here.

  1. To verify it is installed on your Mac, launch Terminal and enter ‘irb’ to start interactive Ruby. If the prompt changes to ‘>>’, enter a simple Hello World program like ‘puts “Hello Ruby on Mac world!”’
  2. To verify it is installed on your Linux computer, open a shell and enter ‘irb’ and , enter a simple Hello World program like ‘puts “Hello Ruby on Linux!”’.
  3. If you have a Windows computer, you need to download and install Ruby, then follow the instructions to test Interactive Ruby on Windows here.

Step 2: Get setup with Eclipse

  1. Download and install Eclipse if you don’t already have it.
  2. Launch Eclipse, then locate and install the Ruby Development Tools plug-in using the Eclipse ‘Help/Install New Software’ menu option. At the Available Software dialog box:
    1. Select –All Available Sites– for the ‘Work with’ drop down list.
    2. Expand the Programming Languages section and select ‘Dynamic Languages Toolkit – Ruby Development Tools’.
    3. Press the Next button, review the options, then select the Finish button.
  3. Use the IDE ‘Eclipse/Preferences’ menu option to pull up the application preferences dialog, then select ‘Ruby’ on the far right of the dialog.
    1. Expand the options under ‘Ruby’ and select ‘Interpreters’. If none are displayed, select the ‘Search…’ button at the right side of the screen to locate any installed interpreters. Apple ships a ruby interpreter – in OSX 10.5.x I found them in /usr/bin/ruby.
  4. Now use the IDE ‘File/New/Ruby Project’ to create a new Ruby project. Name it to any convention you follow (type of project, class, etc.).
    NOTE: You want to use the Ruby Perspective when writing Ruby code, which is available using the IDE ‘Window/Open Perspective/Other’ option and selecting ‘Ruby from the list.
  5. Select ‘File/New/Ruby Class’ to create your first Ruby program. Name it hello, then enter this simple Hello World program to confirm you can create and run a Ruby program:

    class hello
    def hello
    puts “Hello Ruby World”
  6. Save and execute the file and verify you see the text string in the Eclipse console. Congratulations. You just created your first Ruby program using Eclipse.