CSE 341 Lecture Notes - Running Ruby - Quickstart

Ruby itself is designed to load and run files, but doesn't have an interface for interactive use. For interactive use, use 'irb'. You can start up interactive Ruby, and type expressions to be evaluated. Use the load function to load in a program file. Type control-d to exit.

Unfortunately there are a plethora of versions. The latest stable release is 2.2.0. On the undergrad linux machines, the Lab has version 2.0.0 installed; on the undergrad windows machines it's 2.1.5. We are hoping that any version 2 release will be OK for 341, but if in doubt the Official Version for this quarter is 2.0.0, since that is what is on attu.

CSE Lab Machines - Windows

Open a command shell, either by running cmd (a Windows shell) or a cygwin bash shell. Use the cd command to switch to the directory where your Ruby file is (using the Windows shell you separate directories with backward slashes (\) and with cygwin you use forward slashes (/)). After you are in the right directory, type irb to start the Ruby REPL. If you are running a batch program (for example running unit tests), use

ruby mytests.rb

CSE Lab Machines - Linux

Type irb at the prompt to get Interactive Ruby. If the long prompt is getting annoying you can start it with

irb --prompt simple
instead.

To run Ruby on a program file type

ruby yourfilename.rb

The unit test framework may not work out of the box with the linux version of Ruby 2.0.0. If so, to make it work, type this at the command prompt:

gem install minitest
You only need to do this once. (In case you're curious, the gem will end up in this subdirectory .gem/ruby/gems of your home directory.)

Personal Machines

You may already have Ruby on your machine -- make sure you have a version 2 of some sort however. The TAs will be testing your programs using 2.0.0, so if you're using another version, please test your program on 2.0.0 (for example on attu) before turning it in.

You can download Ruby for various platforms from the Ruby home page. It's free.