How to use the Console with MacRuby
Back in 2006, Tim Burks wrote a number of articles for the RubyCocoa web site. One of them, Mastering Cocoa with Ruby, describes an irb-based console (analogous to script/console in Rails) that can be used to experiment with Cocoa-based Ruby code and even modify Cocoa-based Ruby applications "on the fly".
In late 2008, Antonin Hildebrand created a GitHub project that incorporates this tool into a sample MacRuby application. This page explains how to acquire, set up, and use Antonin's project.
Git is a distributed, open-source version control system. GitHub is a Git-based hosting service, specializing in collaborative software development. Both Git and GitHub are worthy of your attention, but right now all we need to know is how to get Git and then how to use it to download a copy of Antonin's project.
Getting Git
First, find out if you already have a copy of Git installed. Type which git into a Terminal session; if it responds with a path name such as /usr/local/bin/git, you're in luck. If not, here's a simple way to get Git (assuming you're running Mac OS X):
- If you have MacPorts installed, simply type sudo port install git-core to download, build and install git.
- In this case, the git binary will be in /opt/local/bin/git and not /usr/local.
- Download a binary Git distribution.
- In a web browser, navigate to http://git.or.cz/#download.
- Under Download/Binaries, click on the link for the "OS X Stable" distribution.
- Click a link to download the appropriate distribution DMG file (eg, Intel, PPC).
- Install the downloaded software.
- Double click on git-* (on your Desktop).
- Follow the steps in the resulting window, as:
- Double click on the "Install Git" icon.
- Follow the resulting Installer commands.
- Check the results.
- Type which git into a Terminal session.
- Look for a response such as /usr/local/bin/git.
Gitting the Project
Now, we get to play with GitHub.
- Navigate to GitHub.
- Using "Search public git repositories", look for macruby-irb.
- Antonin's project is the one saved under woid.
- Click on the macruby-irb link.
- If need be, sign up as a (free) GitHub member.
- Click the "Download" button.
- Download as a tar.gz or zip archive, as desired.
Unpacking the Project
You should now have an archive file (woid-*) on your Desktop.
- Make a copy of the archive, for safety.
- Double click on the archive to unpack it.
The resulting directory is an empty MacRuby project.
- In the Finder, navigate to the build/Release directory.
- Double click on macruby-irb to start the console.
- In the IRB menu, select "Show Console".
Using the Console
You should now see a "MacRuby Console" window, containing an irb session. Try it out, as a sanity check:
irb(main):001:0> 2+2 => 4
To Be Continued...

