Part 2 – This Post
Although not found too often on Windows programming system, the open source programmer’s editor Eclipse is one of the most popular in the world. The Aptana Corporation (now part of Appcelerator) has developed a Ruby and a Ruby on Rails plug in for this popular browser. The Aptana plug-in are fully open sourced. Ruby for Rails version 2.0 is currently supported. In this post we will not discuss The Ruby On Rails plug-in (that’s for a later post), herein we will look at installing Aptana community editor and getting simple Ruby projects up and running. Start by downloading Aptana Studio 2.0 from the Aptana site. We will add RadRails to Aptana Studio after we install the base Aptana system. Although Aptana will allow you to down load just the RadRails Editor, if you do this you will not get the full development environment this way. Trust me. Be sure you select the Windows installer and proceed to install the Aptana Editor just as you would any other Windows product. If you are on Vista (and perhaps Windows 7 – who knows) you will want to modify the shortcut for Aptana as outlined here.
Aptana provides “Perspectives” for developing Ruby and RadRails Projects. For each perspective there are multiple “Views” for working with each project type. Only one perspective can be open at a time but multiple views can (and will) be in use within each perspective. For example with the Ruby Perspective, we can select the GEM view. This will give us a nice GUI with which to add, remove and update the GEMs associated with the current version of Ruby we have installed. Nice.
Let’s start with Ruby (not Ruby on Rails). To start coding: Select ‘”View”, select “Open Perspective” and Select “Ruby”. Select “File”, Select “New”, Select “Ruby Project”. Give your Project A Name: Let’s use “ClassTutorial”. Right Click “ClassTutorial” in the tree view of the Ruby Perspective and select “New” and “Ruby File”. Give this first file the name: “ClasTutorialMain.rb”. A file editor view will open for entering text into this file. Enter the following text into the file editor:
class Person attr_accessor :fname, :lname def initialize(fname, lname) @fname = fname @lname = lname end def to_s @lname + ", " + @fname end end puts 'Create New Person' matz = Person.new("Yukihiro", "Matsumoto") puts matz puts 'exit' exit
Now right click on the view editor. RIght click on extreme right of line #17 and select “toggle breakpoint”. Select “Run” from the main menu and “Debug As” and “Ruby Application”. Now a couple of other ‘views’ will open (Console & Debug). Your screen should look something like this. Note that your step debugger controls are in the top right of the Debug Window. Your watch statements are on the right. Console output will be displayed in the Console window on the bottom. You can, of course, positions these windows as you see fit. While not heaven it is ‘nice’. Either step through the code or press the RED X to terminate the current run. To run without the step debugger select Run/Debug As/Ruby Application.
In the next post we will look at some of this code (and more) as we get our feet wet with Ruby and this IDE.