15110 Fall 2011 [Cortina/von Ronne]

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. In the terminal, open the file .cshrc (Heed the dot!) with gedit by using the command:

    gedit ~/.cshrc &
    
    The existing file should look something like this:
    # Indirect pointer to the global .cshrc file.
    
    source /usr/local/lib/global.cshrc
    #
    
  3. Add the following line to the bottom of .cshrc:

    setenv RUBYLIB /afs/andrew.cmu.edu/usr22/vonronne/public/15110/rubylabs-15110/lib
    
  4. Save the modified .cshrc and exit gedit.

  5. Type the command:

    cp -b /afs/andrew.cmu.edu/usr22/vonronne/public/15110/irbrc ~/.irbrc
    
  6. 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 Source (with a capital "S").

    1. If RubyLabs is working, the result should look like:
      >> Source
      => RubyLabs::Source
      
    2. If RubyLabs is not working, the result will look something like:

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

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 line we added to .cshrc creates an "enviornment variable" called RUBYLIB which gets passed into the irb program and tells irb an extra place to look for Ruby programs. The file .irbrc contains Ruby commands that irb executes at startup. The cp command above copies a version that contains a command to automatically load the rubylabs module (from the place specified by the RUBYLIB enviornment variable).