ruby, meet iphone
DESCRIPTION
RubyMotion transports the dynamic language ethos and Ruby language to iOS all at once. The language is flexible and dynamic. Instead of in dialogs, configuration happens in a text file using a simple internal Ruby DSL. Apps running in the simulator include a REPL for code evaluation. There’s even a built-in way to click on object in an app for dynamic introspection and manipulation. In this talk, we’ll introduce RubyMotion, the platform’s development tools and workflow, and third-party libraries that push the state of the art in iOS developer tools. We’ll show some example apps and reflect on experiences building real-world production apps in Ruby.TRANSCRIPT
Drew Colthorpwww.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 blocksparent= 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 ActiveRecordvalidates 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