---
layout: post
title: "MacRuby"
date: 2008-03-08
comments: false
status: obsolete
reviewed: 2026-10
status_note: >
  MacRuby stopped around 2012 and lived on as RubyMotion. The Mac-native
  language I was hoping for turned out to be Swift (not Ruby, sadly).
categories:
  - ruby
  - MacRuby
  - cocoa
  - Mac OS X
---

Some days ago I found the MacRuby project and it seems it will bring a lot of new things to ruby+cocoa programming. And as I've been reading and writing some RubyCocoa apps in the last months I want to share the joy it gave me.

First of all, it will use the new YARV interpreter that was released with the 1.9 version of ruby last Christmas which is faster than the so called <del class="errata"><span class="sr-only">2008 text: </span>MRV</del><ins class="errata"><span class="sr-only">2026 correction: </span>MRI</ins>[^2026-mri](the "M" is for Matz), also, it doesn't use the ruby garbage collector, but the cocoa one.[^2026-gc] This allows the programs to not stop while the garbage collector is running cause the cocoa garbage collector runs in another thread.

[^2026-mri]: Typo, it was always MRI, Matz's Ruby Interpreter. Since 1.9, YARV is the VM inside MRI, so the two names I was comparing became the same thing.

[^2026-gc]: That was the Objective-C 2.0 garbage collector. Apple deprecated it in OS X 10.8 in favour of ARC (automatic reference counting), and I think that was one of the reasons MacRuby stalled, since it depended on it.

Speaking of threads, another feature of the new ruby 1.9 is that it allows users to use POSIX threads (cool!).[^2026-threads]

[^2026-threads]: Real threads, yes, but the global interpreter lock still let only one run Ruby code at a time. Actual parallel Ruby came much later, with Ractors in Ruby 3.0 (2020).

Another cool feature is named parameters, which are also useful when calling methods. The message style when calling an object's "method" of Objective-C looks like:

```objc
NSAlert *alert = [NSAlert alertWithMessageText: @"What?"
                          defaultButton: @"OK"
                          alternateButton: @"Cancel"
                          otherButton: nil
                          informativeTextWithFormat: @"I am an alert!"];
```

And the MacRuby counterpart:

```ruby
alert = NSAlert.alertWithMessageText("What?",
                defaultButton: "OK",
                alternateButton: "Cancel",
                otherButton: nil,
                informativeTextWithFormat: "I am an alert!")
```

Isn't that sexy?? No more big method names:

```
alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat
```

The last beautiful thing I am going to comment about are ruby hashes inheriting from NSDictionary. That's cool because you can pass a ruby hash to methods that need an NSDictionary instead of constructing one in the cocoa way.

The bad things: MacRuby is under development, it needs Leopard and only runs on Intel Macs. But it looks promising.[^2026m-promise]

[^2026m-promise]: It stayed promising until development stopped around 2012. Its lead developer left Apple and built RubyMotion on the same ideas.
