Check out the tutorial and other learning resources and examples available for MacRuby.

17-18 Apr 2009 » Golden Gate Ruby Conference
San Francisco, CA, USA
Rich Presents MacRuby & HotCocoa
15-16 May 2009 » Ruby on OS X
Amsterdam, Holland, The Netherlands
Laurent & Rich Presenting MacRuby and Hotcocoa
27-29 Aug 2009 » Lone Star Ruby Conference
Austin, Texas, USA
Rich Gives a MacRuby & HotCocoa Tutorial
After several months of development and some slight delays, MacRuby 0.4 is now available. Get it here while it’s still hot!
This is quite an important release that brings new features and fixes several problems. The changes are too numerous to be all mentioned, so here is a selection of the most interesting ones.
The MacRuby garbage collector is now running in multi-threaded mode by default. That means that MacRuby will always do garbage collections on a separate thread and therefore not interrupt the program’s flow.
MacRuby is now fully working in both Intel 32-bit and 64-bit modes. If you are running a recent Mac chances are that it is 64-bit and MacRuby will run faster on it. This is mainly due to the fact that the underlying infrastructure has been significantly improved for 64-bit processors.
DTrace probes have been added to the core of the interpreter. You can now trace various things such as method calls or exceptions. All of that can be done on any MacRuby processes in the system.
provider macruby {
probe insn__entry(char *insnname, char *sourcefile, int sourceline);
probe insn__return(char *insnname, char *sourcefile, int sourceline);
probe method__entry(char *classname, char *methodname, char *sourcefile, int sourceline);
probe method__return(char *classname, char *methodname, char *sourcefile, int sourceline);
probe raise(char *classname, char *sourcefile, int sourceline);
probe rescue(char *sourcefile, int sourceline);
};
DTrace is a very powerful tool that has proven to be extremely useful when debugging live applications. MacRuby ships with several DTrace scripts in /Developer/Examples/Ruby/MacRuby/DTrace to profile various things such as method count, duration or even objects collected by the GC.
MacRuby now exposes an Objective-C API that can be used to control the runtime from a pure Cocoa environment.
$ cat hello_macruby.m
#import <Foundation/Foundation.h>
#import <MacRuby/MacRuby.h>
int main(void) {
id proc = [[MacRuby sharedRuntime] evaluateString:@"proc { |x| puts \"hello #{x}\"}"];
[proc performRubySelector:@selector(call:) withArguments:@"MacRuby"];
return 0;
}
$ gcc hello_macruby.m -o hello_macruby -framework Foundation -framework MacRuby -fobjc-gc
$ ./hello_macruby
hello MacRuby
It should be helpful if you are working on an Objective-C Cocoa application and are considering using MacRuby to either implement new functionalities or to provide a scripting interface to your native objects.
A “MacRuby Core Data Application” template is now available, as well as an “Embed MacRuby” target. The latter can be used to embed MacRuby.framework inside your application bundle. Embedding the framework allows you to distribute your application to users and not require them to install MacRuby.
HotCocoa is a thin, idiomatic Ruby layer that sits above Cocoa and other frameworks. It was introduced in MacRuby 0.3 and it has been significantly improved in 0.4.
New mappings for XML parser, KVO array/set accessors, property lists and more AppKit components were added as well as lots of bug fixes and improvements.
A “deploy” task was added to the project’s Rakefile. This new task prepares an application for deployment by embedding the MacRuby runtime inside its bundle (similar to what the Xcode’s Embed MacRuby target does). Once the “macrake deploy” task is complete, you can share your .app with friends who do not have MacRuby installed on their machine.
But the most interesting change is probably the new graphics layer, called HotCocoa::Graphics. It provides a simple object-oriented interface into the power of Mac OS X’s Core Graphics and Core Image drawing libraries.
Over the list of minor changes, Set has been reimplemented on top of NSSet and NSNumber implements the Numeric methods. Finally, the standard library was updated to Ruby 1.9.1’s version.
While MacRuby 0.4 turns out to be pretty stable when it comes to Cocoa development, there are still a few problems with C extensions, RubyGems and Ruby IOs. We recommend to use the corresponding Cocoa APIs (when they exist) in the meantime we work on these issues.
We hope that you will enjoy this release. Please let us know if you find any problems.
Stay tuned for more details about the next release: 0.5, which will be focusing on performance.