Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
What I've learned about RubyMotion

I’ve been trying to learn RubyMotion recently, using Ruby to develop iOS appeals to me.

I have no prior Objective-C or Cocoa API knowledge besides the basic HelloWorld. I’ve been using this tutorial and have learned more about Cocoa API faster using Ruby than with Objective-C. There is less boilerplate code that needs to be written for defining interfaces and implementations.

The main takeaway of RubyMotion is that it is not your standard Ruby implementation. It is a Ruby runtime wrapped around the Objective-C runtime. All Ruby objects map directly to there corresponding Objective-C object — Array to NSMutableArray, Hash to NSMutableDictionary, etc. RubyMotion does not come with the standard library as other flavors, you are relying on Cocoa API as the standard library.

There is even a difference in Ruby syntax to map directly to Objective-C. The Objective-C language does message passing for “method invocation”. This means that a method call on an object is determined by parameters rather than just method name. RubyMotion had to include this language feature, so you will actually see Ruby that is invalid all other Ruby flavors.

class MyObject
    def doSomething(doSomething, argument: argument)
    end

    #This does not override the method defined above
    def doSomething(doSomething, anotherArgument: argument)
    end
end

Luckily there are extensions for your favorite editors. Rubymine even supports MacRuby syntax, but does not support autocomplete, yet.

Two weeks ago, I saw a talk about RubyMotion from its creator in Berlin. He gave the basic HelloWorld demonstration, but also gave an introduction in the community. It is small, but great things are coming out of it.

The community has started taking the power of Ruby and making the libraries and DSL-y things we love in Ruby.

  • BubbleWrap is a resource API. It gives you easy access to JSON parsing, HTTP requests, alerts, etc. It is kind of catch all of lower-level Cocoa API tasks that you don’t want to have to write your own helpers for.
  • Formotion is a DSL to create Forms. Usually you use Interface Builder to build forms and load the appropriate NIB. This gem will allows you to define a form in code.
  • MotionData is ActiveRecord like access to CoreData. It supports migrations, scopes, basic validations, etc.
  • SimpleView provides a DSL for formatting views.

With all this, there is one question that always gets asked. Is RubyMotion worth it? Yes! Laurent, the creator, is in it to win it! This is why he charging for the RubyMotion; funding ensures that he can continue to work on it.

From a Pivot role, I’ve had to discover RubyMotion’s position in testing. Pivotal Labs is a pure TDD shop, everything from Java, Objective-C, Javascript, and Ruby is tested.

RubyMotion comes with a prebuilt RSpec (actually a port of bacon) like testing framework. The testing framework supports the testing of views and controller using the UIAutomation framework. I think that we can agree that it could be better, but I believe there is enough to get started and allow us to expand on it.

The RubyMotion community is still growing. I look forward to see what comes out of it, so that I can use Ruby in other devices.

Comments
  1. Alex Koppel says:

    Thanks for the blog post! I’ve had a low-grade burning desire to try RubyMotion for a while, and I think it’s time to take the plunge.

    Knowing that it’s a thin wrapper around the Objective-C libraries is useful. I wonder if it’d be a worthwhile project to try to port chunks of the Standard Library to RubyMotion, or if that’s an unnecessary layer obfuscation…

  2. Great musings on your first look into RubyMotion! I’m intrigued by the possibilities of using RubyMotion for native iOS development instead of going through the PhoneGap/Apache-Cordova approaches.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *