Chapter 9. HotCocoa
Interface Builder is the de facto standard for building user interfaces for all manner of Cocoa applications (whether you’re using Objective-C, MacRuby, Nu, or whatever other exotic language that talks to Cocoa), but sometimes it’s nice to have a more accessible way to persist your user interface code. You can probably think of plenty of instances where you’ve wanted to look at the code that Interface Builder was generating but couldn’t. For developers who don’t like to use a visual tool like Interface Builder or would rather create their UI programmatically, there’s an easy solution called HotCocoa. HotCocoa is a library written by Rich Kilmer that gives you that access by letting you specify your UI (and more) in Ruby.
If you’ve looked at much Ruby code you can probably remember at least one moment when you stood back and admired its beauty. Ruby’s flexible syntax allows you to build some useful and elegant domain-specific languages (DSLs). For example, the Sinatra web framework helps you create web applications with a simple DSL:
This little snippet creates a web application that lives at http://localhost/hotcocoa and that renders something like “HotCocoa is still awesome at 03/02/2011 13:31:12,” but you could probably figure that out from reading the code.