Problems running Ruby program

Sam Kuper's Avatar

Sam Kuper

21 Jun, 2011 02:33 PM

I'm using Eclipse 3.6.2.r362_v20110210 with the Aptana Studio plugin version 3.0.2.201106082253 (i.e. all fully up-to-date, I believe) on Mac OS X 10.6.7 Snow Leopard on a Macbook.

I created a Ruby project, and then created a single file inside it called "item.rb", into which I wrote some Ruby code.

The file is very short: it defines an "Item" class with an initialisation method that asks the user for a value (using a "puts" followed by a "gets.chomp") and a get method that returns the value, and it also contains two more lines: one to create a new Item, and one to call that method on the newly-created Item.

When I run "ruby item.rb" from the Terminal, it works as expected: it asks the user for a value, and returns that value. No errors/warnings.

Now, I don't want to have to use the Terminal every time I want to execute the file, but I'm having trouble getting it running any other way.

Here are the steps to reproduce:

  • In the main Eclipse menu, go to Window > Open Perspective > Other.
  • In the resulting dialogue box, click "Ruby" and click "OK".
  • In the Script Explorer view, click the triangle next to the name of the project containing the file I want to run, so that the project's contents are shown.
  • In the Script Explorer view, double-click on the name of the file I want to run (item.rb).
  • This causes item.rb to open in an editor view, and gives that view focus (i.e. the editor view containing item.rb has a blue rather than a grey border, and there is an active cursor inside the view).
  • Click the "Run" button on the Eclipse toolbar (the one that looks like a green "Play") button.
  • THE FIRST PROBLEM: a "Run as..." dialogue box pops up (I don't know why) asking me to "Select a way to run 'item.rb'". It gives me two options (again, I don't know why): "Android Application", "Ruby Application".
    • Expected behaviour: because item.rb is a file ending in ".rb" and containing only valid Ruby code, Eclipse/Aptana should, by default, run it as a Ruby application.
  • I click "Ruby Application", and then click "OK".
  • THE SECOND PROBLEM: the dialogue box disappears, but nothing else happens.
    • Expected behaviour: the Console view should get focus, and item.rb should be executed, with the results showing up in the Console view's textarea.
  • By this point, it would be reasonable to give up. But programmers are unreasonably persistent, right? So: click the Console tab.
  • The Console view's header says, "item.rb [Ruby Application] /usr/bin/ruby", and below this is a blank textarea containing only a blinking cursor.
  • Press the <Return/Enter> key on the Macbook's keyboard.
  • THE THIRD PROBLEM: the Console view's textarea suddenly updates with the output of item.rb, but weirdly, it doesn't stop at gets.chomp, it just acts as though the user has entered an empty response at that stage (i.e. as though the user has simply pressed the <Return/Enter> key on the keyboard), and ploughs on until the entire program has executed. The Console view's header then changes to "<terminated> item.rb [Ruby Application] /usr/bin/ruby".
    • Expected behaviour: item.rb should execute in the Console view just as it does in the Terminal.

Please can you help me troubleshoot these three problems?

Many thanks.

(Update: edited to fix a few grammar and Markdown issues.)

  1. 2 Posted by Sam Kuper on 22 Jul, 2011 09:41 AM

    Sam Kuper's Avatar

    Please feel free to reply here or over at StackOverflow: http://stackoverflow.com/questions/6782683

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac