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
Blog Overview
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.
The Apple Developer Connection (ADC) website is now featuring an article about MacRuby, titled Developing Cocoa Applications Using MacRuby. This article will introduce you to MacRuby and guide you through the process of writing a Cocoa application with it.
Enjoy, and do not hesitate to contact us if you have any question!
It is a great pleasure to announce the immediate availability of MacRuby 0.3! We have been working very hard on this release for several months and, while it’s still a developer release, we hope that you will give it a try. Get it while it’s still hot!
First of all, MacRuby now ships with a core library called HotCocoa, something which greatly simplifies Cocoa programming while also using simple Ruby idioms. Rich Kilmer is the man behind this amazing work. You will find several examples in /Developer/Examples/Ruby/MacRuby/HotCocoa, and some initial bits of documentation in http://www.macruby.org/trac/wiki/HotCocoa (which will be improved very soon).
require 'hotcocoa' include HotCocoa application do |app| window :size => [100, 50] do |win| b = button :title => 'Hello' b.on_action { puts 'World!' } win << b end end
We also support Interface Builder in this release. You can define classes, outlets and actions in a MacRuby Xcode project and they will automatically appear in Interface Builder. We have a new Ruby metadata parser that works for both RubyCocoa and MacRuby files. The parser is written in MacRuby and uses the amazing ripper extension that comes with it to extract the parser tokens.
Finally, of course, lots of bugs were fixed. We now have a pretty good Cocoa support and can run most of the LimeChat application (which is currently being ported from RubyCocoa). We also re-implemented the PagePacker application from Objective-C, which now ships as an example in the MacRuby distribution. On the pure Ruby side of things, a lot of bugs have been fixed and we are now able to run some commands of RubyGems. Installing simple gems should work. Don’t expect MacRuby to run Rails yet, though!
MacRuby is progressively turning more stable with every release. Please give it a try and report any problem you find! If you want to join the project and help, volunteers are also greatly welcome!
« newer | Page 1 of 3 | older »