Last Updated: February 25, 2016
· supremegravity

More rubyesque Cocoa calls with Sugarcube

Sugarcube papers over the ridiculously verbosity of iOS's APIs so you can feel like you're writing ruby again:


replaces the default RubyMotion way to open a URL:


If you were slogging away in Objective-C, you'd end up writing this beauty:

NSURL *url = [ [ NSURL alloc ] initWithString: @"" ];
[[UIApplication sharedApplication] openURL:url];


Sugarcube includes UIKit helpers, type transforms, constants, REPL helpers, CoreGraphics, and more--there are three great sources that, together, document all of this:

The original author's overview is a great place to start.

The README on github goes deeper.

For docs on all the methods see the RubyDoc pages, e.g. UIImage on RubyDoc

Four examples

  1. Scale an image "my_image".uiimage.scale_to [37, 37].

  2. Slide a view smoothly to the left? view.slide(:left, 20).

  3. Quickly post a notification: "my notification".post_notification

  4. Put a text label into a view in one line view << ('Goodbye'.italic + ' cruel world.').underline.uilabel.