15110 SPRING 2013

RubyLabs Setup Instructions

The author of the text book has created a library of modules called RubyLabs to support the tutorials and projects in the text book. These instructions describe how to enable the use of the RubyLabs modules for you andrew id user account. This will enable you to use the RubyLabs modules on the Gates Hall Cluster machines and when ssh'ing into unix.andrew.cmu.edu

Procedure

  1. Get a terminal logged in to a GHC machine or unix.andrew.cmu.edu.

    1. If you are physically sitting at a Gates Hall Cluster machine, this can be accomplished by selecting the "Terminal" option from the "System Tools" submenu of the "Applications" menu at the upper-left corner of the desktop.
    2. If you are physically somwhere else, you may ssh (with X11 forwarding) into unix.andrew.cmu.edu.
  2. At the command prompt, in the terminal, enter the command:

         
        /afs/cs/academic/class/15110-s13/bin/rubylabs-15110/bin/lab-setup.rb
    
       

    This will produce output similar to the following:

       Backing up .irbrc to .irbrc~
       Creating updated .irbrc:
       IRB.conf[:PROMPT_MODE] = :SIMPLE
       require 'rubylabs'
       require 'rubygems'
       ** .irbrc configuration: OK
       Adding environment variable to .cshrc:
       ** .cshrc configuration: OK
       Adding environment variable to .bashrc:
       ** .bashrc configuration: OK
      
  3. Log out of the GHC/unix.andrew.cmu.edu system and, then, log back in.

How do I know if it worked?

  1. Open a terminal with a command-line.

  2. Run irb.

  3. Ask Ruby to evaluate the expression hello (with a lowercase "h").

    1. If RubyLabs is working, the result should look like:
      >> hello
      => "Hello, you have succesfully installed RubyLabs!"
      
    2. If RubyLabs is not working, the result will look something like:

      irb(main):001:0> hello
      NameError: uninitialized constant hello
      	from (irb):1
      	from :0
      

This will likely not work if you did not first log out and log back in after running /afs/cs/academic/class/15110-s13/bin/rubylabs-15110/bin/lab-setup.rb

What about graphics?

RubyLabs provides a Canvas object for graphical output. In addition, to irb needing to be able to find RubyLabs. RubyLabs will need to be able to find the X11 graphics subsystem. If you are at one of the machines in the Gates Hall Cluster, it should work. If you are accessing remotely, you will need to have X11 and ssh configured correctly (just like you do for running gedit remotely).

You can test the RubyLabs canvas by typing the following command in irb:

Canvas.init(300,300,"HelloWorld")

If everything is working correctly, a window with the title "RubyLabs::HelloWorld" will pop up.

Explanation

Linux/UNIX allows file names to start with a dot, but these are considered special and are usually not displayed to the user. Many programs read from particular "dot files" in the user's home directory to configure themselves at startup. The ".cshrc" file is used by csh (which is the program that gives you the command line to type in your commands within the terminal); it contains a list of commands to be executed when the terminal is opened. The setup-rubylabs.sh program adds a line to .cshrc that creates an "enviornment variable" called RUBYLIB which gets passed into the irb program and tells irb an extra place to look for Ruby programs. It also creates a file .irbrc and makes a back up copy of any pre-existing file of that name. The file .irbrc contains commands that irb executes when it is started. The version it creates contains a command to automatically load the rubylabs module (from the place specified by the RUBYLIB enviornment variable).