Ruby and Cocoa

 

Ruby and Cocoa

It seems that Ruby language and OSX Cocoa API don’t mix well in every scenario. It is common knowledge that making these two work together is as easy as using RubyCocoa or MacRuby. These however are not universal tools; let me show you some use cases below.

The important thing to remember is that the solutions above (i.e. RubyCocoa and MacRuby) are not libraries.

RubyCocoa is an OSX framework applied into the ruby environment through interpreter patching. Such architecture gives greater flexibility: RubyCocoa does not provide a set of Cocoa bindings, it builds a bridge between these two environments (with lazy loading and other benefits).

MacRuby, also an OSX framework, is an implementation of ruby language that is tightly integrated with OSX. It features better performance, many architecture improvements (Ruby objects implemented on top of native Objective-C constructs) and better support of standard development flow (e.g. InterfaceBuilder compatibility).

These two frameworks prove useful in a scenario where an OSX desktop application is being built. Notably MacRuby provoked many positive reactions (e.g. 3 areas where MacRuby shines vs Objective-C) and some people believe that MacRuby will eventually replace Objective-C. Sumarizing, it provides significant gains in code verbosity while sacrificing relatively little performance.

However MacRuby or RubyCocoa are inaccessible in any interpreter independant environment. Currently most ruby developers use RVM, with their interpreter of choice. When writing a console program with native system functionality, there is a tough choice to make. The options are: order users to patch their interpreters with RubyCocoa, make them use specific MacRuby interpreter, or disregard these tools and resort to plain old C bindings.


Leave a Reply

Your email address will not be published. Required fields are marked *

*

Comment

You may use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>