Drew Colthorp
www.atomicobject.com
iPhone, meet Ruby
@atomicobject http://spin.atomicobject.com
A Tour of RubyMotion
• Implementation of Ruby
• Similar object model to Objective C, natural language for
the platform
• UNIX Ethos
• Very Flexible
From our app
directory, we can run
our app in the
simulator with a
simple command.
From-scratch implementation of Ruby.
Started by apple in 2007.
© HipByte SPRL
© HipByte SPRL
@atomicobject http://spin.atomicobject.com
Garbage Collection
(Sort of. Auto-release and retain, similar to ARC.)
(App idea shamelessly ripped off from HipByte.)
@atomicobject http://spin.atomicobject.com
Ruby
Classes and methods; no header files; rest arguments.
What you don’t see in the usual case is the flexibility of Ruby.
Method invocation syntax.
Keyword args: added to RubyMotion for Obj-C compatibility,
now standard in Ruby 2.0.
do is syntax for blocks. Very similar to Objective C blocks
parent= is just a method assumed to exist on el. Aliases to
setParent if el is an Objective C object.
These features of ruby make it great for creating internal DSLs.
Why create separate parsers for incomplete languages when your
primary language is so flexible?
Unlike most languages, there are no contexts where you can’t put code.
For example, within a class definition, you can do whatever you want.
For example, we could put a print statement in our class def.
This is how you’d normally write it.
Checking of valid objects in ActiveRecord
validates is a method on class objects inheriting from ActiveRecord::Base
@atomicobject http://spin.atomicobject.com
Rake
@atomicobject http://spin.atomicobject.com
Specs
@atomicobject http://spin.atomicobject.com
REPL
Now, if we hold command and click on an
element, the context of our REPL changes to
the clicked element. Right now our REPL says
(main), meaning we haven’t clicked an element.
If we command-click our text-box, we see
UILabel:0xf975. Now “self” refers to that element.
So we can set self.backgroundColor to see it change to red.
Or we can tweak frame size to get the positioning just right.
@atomicobject http://spin.atomicobject.com
What about
Objective-C?
@atomicobject http://spin.atomicobject.com
Apps
© 37signals
@atomicobject http://spin.atomicobject.com
The End

Ruby, Meet iPhone