Nameless parameters in RubyMotion
While working on an iOS app for a client I came across an interesting language-level bug (or missing feature?) in RubyMotion.
The app has a fancy animation which needed a method on CAMediaTimingFunction called functionWithControlPoints. It turns out that this is one of the places you’ll see a seldom used feature of Objective-C: Nameless Parameters.
A function with Nameless Parameters can be defined like so:
… and instead of the usual key: value style invocation you can simply omit the keys:
It’s a neat trick, but one that Apple actively discourages and it seems the RubyMotion team aren’t too keen either:
Nameless Objective-C parameters are the most hideous thing I have ever had the displeasure to work with. Also completely unnecessary.— Eloy Durán (@alloy) March 28, 2014
Fortunately they crop up in few places, but unfortunately for us CAMediaTimingFunction is one of them and RubyMotion doesn’t support the syntax (check out the discussion in RM-123).
With a little
magic meta-programming you can poke still poke at the method, here’s
what I ended up doing:
Eloy suggested a more general purpose workaround in the mentioned ticket.