ruby, meet iphone

76
Drew Colthorp www.atomicobject.com iPhone, meet Ruby

Upload: atomic-object

Post on 15-May-2015

2.607 views

Category:

Technology


2 download

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

Page 2: Ruby, Meet iPhone

@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

Page 3: Ruby, Meet iPhone
Page 4: Ruby, Meet iPhone
Page 5: Ruby, Meet iPhone
Page 6: Ruby, Meet iPhone

From our app directory, we can run

our app in the simulator with a

simple command.

Page 7: Ruby, Meet iPhone

From-scratch implementation of Ruby.Started by apple in 2007.

Page 8: Ruby, Meet iPhone

© HipByte SPRL

Page 9: Ruby, Meet iPhone

© HipByte SPRL

Page 10: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

Garbage Collection(Sort of. Auto-release and retain, similar to ARC.)

Page 11: Ruby, Meet iPhone
Page 12: Ruby, Meet iPhone
Page 13: Ruby, Meet iPhone
Page 14: Ruby, Meet iPhone

(App idea shamelessly ripped off from HipByte.)

Page 15: Ruby, Meet iPhone
Page 16: Ruby, Meet iPhone
Page 17: Ruby, Meet iPhone
Page 18: Ruby, Meet iPhone
Page 19: Ruby, Meet iPhone
Page 20: Ruby, Meet iPhone
Page 21: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

Ruby

Page 22: Ruby, Meet iPhone
Page 23: Ruby, Meet iPhone

Classes and methods; no header files; rest arguments.What you don’t see in the usual case is the flexibility of Ruby.

Page 24: Ruby, Meet iPhone

Method invocation syntax.

Page 25: Ruby, Meet iPhone

Keyword args: added to RubyMotion for Obj-C compatibility, now standard in Ruby 2.0.

Page 26: Ruby, Meet iPhone

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.

Page 27: Ruby, Meet iPhone

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?

Page 28: Ruby, Meet iPhone

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.

Page 29: Ruby, Meet iPhone

For example, we could put a print statement in our class def.

Page 30: Ruby, Meet iPhone
Page 31: Ruby, Meet iPhone
Page 32: Ruby, Meet iPhone

This is how you’d normally write it.

Page 33: Ruby, Meet iPhone

Checking of valid objects in ActiveRecordvalidates is a method on class objects inheriting from ActiveRecord::Base

Page 34: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

Rake

Page 35: Ruby, Meet iPhone
Page 36: Ruby, Meet iPhone
Page 37: Ruby, Meet iPhone
Page 38: Ruby, Meet iPhone
Page 39: Ruby, Meet iPhone
Page 40: Ruby, Meet iPhone
Page 41: Ruby, Meet iPhone
Page 42: Ruby, Meet iPhone
Page 43: Ruby, Meet iPhone
Page 44: Ruby, Meet iPhone
Page 45: Ruby, Meet iPhone
Page 46: Ruby, Meet iPhone
Page 47: Ruby, Meet iPhone
Page 48: Ruby, Meet iPhone
Page 49: Ruby, Meet iPhone
Page 50: Ruby, Meet iPhone
Page 51: Ruby, Meet iPhone
Page 52: Ruby, Meet iPhone
Page 53: Ruby, Meet iPhone
Page 54: Ruby, Meet iPhone
Page 55: Ruby, Meet iPhone
Page 56: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

Specs

Page 57: Ruby, Meet iPhone
Page 58: Ruby, Meet iPhone
Page 59: Ruby, Meet iPhone
Page 60: Ruby, Meet iPhone
Page 61: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

REPL

Page 62: Ruby, Meet iPhone
Page 63: Ruby, Meet iPhone

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.

Page 64: Ruby, Meet iPhone

If we command-click our text-box, we see UILabel:0xf975. Now “self” refers to that element.

Page 65: Ruby, Meet iPhone

So we can set self.backgroundColor to see it change to red.Or we can tweak frame size to get the positioning just right.

Page 66: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

What about Objective-C?

Page 67: Ruby, Meet iPhone
Page 68: Ruby, Meet iPhone
Page 69: Ruby, Meet iPhone
Page 70: Ruby, Meet iPhone
Page 71: Ruby, Meet iPhone
Page 72: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

Apps

Page 73: Ruby, Meet iPhone

© 37signals

Page 74: Ruby, Meet iPhone
Page 75: Ruby, Meet iPhone
Page 76: Ruby, Meet iPhone

@atomicobject http://spin.atomicobject.com

The End