Ruby, Meet iPhone

3,364 views

Published on

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.

Published in: Technology

Ruby, Meet iPhone

  1. 1. Drew Colthorpwww.atomicobject.comiPhone, meet Ruby
  2. 2. @atomicobject http://spin.atomicobject.comA Tour of RubyMotion• Implementation of Ruby• Similar object model to Objective C, natural language forthe platform• UNIX Ethos• Very Flexible
  3. 3. From our appdirectory, we can runour app in thesimulator with asimple command.
  4. 4. From-scratch implementation of Ruby.Started by apple in 2007.
  5. 5. © HipByte SPRL
  6. 6. © HipByte SPRL
  7. 7. @atomicobject http://spin.atomicobject.comGarbage Collection(Sort of. Auto-release and retain, similar to ARC.)
  8. 8. (App idea shamelessly ripped off from HipByte.)
  9. 9. @atomicobject http://spin.atomicobject.comRuby
  10. 10. Classes and methods; no header files; rest arguments.What you don’t see in the usual case is the flexibility of Ruby.
  11. 11. Method invocation syntax.
  12. 12. Keyword args: added to RubyMotion for Obj-C compatibility,now standard in Ruby 2.0.
  13. 13. do is syntax for blocks. Very similar to Objective C blocksparent= is just a method assumed to exist on el. Aliases tosetParent if el is an Objective C object.
  14. 14. These features of ruby make it great for creating internal DSLs.Why create separate parsers for incomplete languages when yourprimary language is so flexible?
  15. 15. 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.
  16. 16. For example, we could put a print statement in our class def.
  17. 17. This is how you’d normally write it.
  18. 18. Checking of valid objects in ActiveRecordvalidates is a method on class objects inheriting from ActiveRecord::Base
  19. 19. @atomicobject http://spin.atomicobject.comRake
  20. 20. @atomicobject http://spin.atomicobject.comSpecs
  21. 21. @atomicobject http://spin.atomicobject.comREPL
  22. 22. Now, if we hold command and click on anelement, the context of our REPL changes tothe clicked element. Right now our REPL says(main), meaning we haven’t clicked an element.
  23. 23. If we command-click our text-box, we seeUILabel:0xf975. Now “self” refers to that element.
  24. 24. So we can set self.backgroundColor to see it change to red.Or we can tweak frame size to get the positioning just right.
  25. 25. @atomicobject http://spin.atomicobject.comWhat aboutObjective-C?
  26. 26. @atomicobject http://spin.atomicobject.comApps
  27. 27. © 37signals
  28. 28. @atomicobject http://spin.atomicobject.comThe End

×