CSE 341 Lecture Notes - Running Ruby - Quickstart

In addition to the notes below, also see the Ruby directions from CSE 341 Winter 2018.

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.5.1. The undergrad linux machines have 2.2.9. You need to have some version of Ruby 2, but based on recent installation troubles, we recommend you not use Ruby 2.3.0 and perhaps not 2.3.x for any x for the Tetris assignment (HW 7). HW 8 doesn't use graphics, so will be less picky. We are hoping that any version 2 (except 2.3 for some reason) release will be OK for 341, but if in doubt the Official Version for this quarter is 2.2.9, since that is what is on attu.

Type irb at the command prompt to get Interactive Ruby. We suggest using the --prompt simple and --noinspect options to get Ruby to have a less verbose prompt, and to use to_s to print the results of evaluating an expression in the top-level read-eval-print loop. In other words use this:

irb --prompt simple --noinspect

If you don't want to type this every time, put the following in a file named .irbrc in your home directory:

IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:INSPECT_MODE] = false

You will need to be able to run the tk graphics package and the unit test package. You can test whether these are on your machine by starting interactive Ruby using irb. Then at the prompt type

  require 'tk'
  require 'minitest/autorun'
  

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 (or better irb --prompt simple --noinspect).

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. 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 (except 2.3) of some sort however. The TAs will be testing your programs using 2.2.9, so if you're using another version and are unsure about compatibility, please test your program on 2.2.9 (for example on attu) before turning it in.

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

Mac OS

High Sierra comes with version 2.3.3, which will be ok for HW 8 but not the Tetris assignment (HW 7). See Ruby directions from CSE 341 Winter 2018 for details on installing Ruby on a Mac.

One addition to the Winter 2018 directions: you will also need to have the unit test gem installed. Check if it's already there by starting irb and at the prompt typing

 require 'minitest/autorun' 

If it's not there, at the terminal type gem install minitest

Windows

Installing Ruby on Windows is mostly straightforward, although there can be issues getting Tk to work.

To install on Windows, follow these steps: