Using Ruby and irb in CSE 341Fall 2011 (Last updated: November 28, 2011)OverviewThe last two homeworks will be using the Ruby language. We recommend editing your files in emacs andusing irb, which is Ruby’s REPL. This document describes basic installation and usage steps sufficient fordoing your homework. Unlike when we used SML, we recommend running the REPL from a terminal (shell)window, not from within emacs. This is described below.For installation purposes related to Homework 6, there are some key facts:• You need to have some version of Ruby 1.8.7, not Ruby 1.9. An earlier version of Ruby 1.8 mightwork, but it is hard to be sure.• You need to have a version of the Tk graphical toolkit and the appropriate Ruby libraries for using it.• If you have emacs version 23 (the current version), you should not need to configure it in any specialway for using Ruby: opening a file with extension .rb should use Ruby mode.This document is long, but only because we are giving information for various operating systems and choicesfor using or not using resources from the department (lab machines, virtual machines, remote machines).Just find the section that is most convenient for you.Also notice the last section of this document, “General information on using the REPL (or not)” which hasinformation relevant to all operating systems.See the course website for the main links for the Ruby language, library documentation, etc.Using Windows in the Department Undergraduate Labs• You do not need to install any software.• Create a Ruby file (e.g., by downloading the provided code and renaming it) wherever is convenient(e.g., where you have been storing your other homework assignments). Do not store it on thedesktop or under C:\ because all changes to these directories get erased when you log out.Store your files under Z:\ (your directory on the department file system) or somewhereelse (e.g., on a personal usb drive).• Open emacs however is convenient. You should be able to find it by, e.g., typing emacs in the “SearchPrograms and Files” from the Start Menu.• Open your Ruby file in emacs, by dragging it from an Explorer window onto emacs, or by Ctrl-x Ctrl-fand then entering the full path to the file, or by using the File menu. Edit and save the file as usual.• In 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 youseparate directories with backward slashes (\) and with cygwin you use forward slashes (/)). Afteryou are in the right directory, type irb to start the Ruby REPL.1Using your own Windows machine• If you did not install emacs version 23.3 earlier in the course, do so using the instructions for the SMLportion of the course. Note you do not need SML mode — all you need to do is install emacs.• Go to http://www.rubyinstaller.org/, click on the giant Download button, and click on the Ruby1.8.7-p352 RubyInstaller (not a Ruby 1.9 installer).• Run the installer.– Accept the License.– On the next screen, click all three boxes: Install Tcl/Tk support, Add Ruby exe-cutables to your PATH, and Associate .rb and .rbw files with this Ruby installation.– Then click Install.• Create a Ruby file (e.g., by downloading the provided code and renaming it) wherever is convenient(e.g., where you have been storing your other homework assignments).• Open emacs however is convenient, e.g., from the Start Menu.• Open your Ruby file in emacs, by dragging it from an Explorer window onto emacs, or by Ctrl-x Ctrl-fand then entering the full path to the file, or by using the File menu. You can now edit and save thefile as usual.• In Windows, open a command shell by running cmd (a Windows shell). Use the cd command toswitch to the directory where your Ruby file is (using the Windows shell you separate directories withbackward slashes (\)). After you are in the right directory, type irb to start the Ruby REPL.Using Linux in the Department Undergraduate Labs• You do not need to install any software.• Create a Ruby file (e.g., by downloading the provided code and renaming it) wherever is convenient(e.g., where you have been storing your other homework assignments).• Open emacs however is convenient (one way is to find it under the large list of applications).• Open your Ruby file in emacs by Ctrl-x Ctrl-f and then entering the full path to the file, or by usingthe File menu. You can now edit and save the file as usual.• Open a command shell however is convenient (one way is to find the terminal program under the largelist of applications).• Use the cd command to switch to the directory where your Ruby file is (separating directories withforward slashes). After you are in the right directory, type irb to start the Ruby REPL.Using your own Linux machineMost Linux distributions should make it easy to install Ruby 1.8.7 and connect it to the Tk graphics library.Beware the “ruby” package, which may or may not be Ruby 1.9 — you may have to choose a ruby1.8package explicitly. If irb is a separate package, install that too, again looking for an explicit use of 1.8. Afterinstallation, running ruby --version should indication ruby 1.8.7.After installation, you can follow the instructions for, “Using Linux in the Department Undergraduate Labs.”2Using the Department’s Linux Virtual Machine on your machineThe department provides a Linux virtual machine that runs on your own computer no matter what operatingsystem is on your computer. These instructions assume you already have that installed and you are “in” thevirtual machine. Note that as of Fall 2011, the virtual machine requires you to have a 64-bit machine.• Open a command shell however is convenient (one way is to find the terminal program under the largelist of applications).• Run the command sudo yum install ruby irb ruby-tcltk.• You can now follow the instructions for, “Using Linux in the Department Undergraduate Labs.”Using your own Mac machineWe do not recommend trying to get Ruby to work with Tk directly under Mac OS (option 4below). Ruby 1.8.7 itself works fine and is probably already installed, but that is not enough for Homework6. Success may depend on the exact version of your operating system and the graphics in homework 6 stilldo not work quite as expected. We recommend options 1–3.Option 1:The department has made available a solution where you
View Full Document