Archive for the ‘cocoa’ Category

Programming Cocoa With MacRuby: Part One

In this series of articles, I will work through the Pragmatic Programmer book Programming Cocoa with Ruby by Brian Marick, porting the examples to MacRuby.

Examples from Chapter 2

The first few examples are almost identical. require 'osx/cocoa' becomes framework 'cocoa'. MacRuby lets us use the familiar instead of SomeObject.alloc.init, and there is no need to explicitly inherit from NSObject, since NSObject replaces Object in the standard class hierarchy:

irb(main):011:0> class Foo;end;Foo.ancestors
=> [Foo, NSObject, Kernel]


#!/usr/bin/env macruby
framework 'cocoa'


#!/usr/bin/env macruby
framework 'cocoa'

class AppDelegate
  def applicationDidFinishLaunching(aNotification)
    puts "#{} makes me say: Hello, world"

our_object =

Pages: 1 2 3

“Ruby Rocks” ported to MacRuby

MacRuby logoWhen I first started playing around with writing Cocoa apps using Ruby, I was using RubyCocoa. I did the Ruby Rocks tutorial and was pretty impressed by how easy it was to write graphics apps using Ruby and Cocoa. I quickly discovered MacRuby and decided to use it going forward. The first thing I did was to port my finished Ruby Rocks to MacRuby, so I’m posting in as a MacRuby sample.

Possibly at some point I will write up the conversion to MacRuby as a tutorial. Anywhere, here it is. You can see that I kept playing for a while after finishing the tutorial…


Return top

Web Application Developer

LastObelus hacks on web applications for enterprise. Usually in Rails or Merb these days, but he has worked WebObjects, J2EE, and various PHP frameworks.