Summarized using AI

Inside RubyMotion

Rich Kilmer • November 01, 2012 • Denver, Colorado • Talk

The talk "Inside RubyMotion" presented by Rich Kilmer at RubyConf 2012 discusses RubyMotion, an innovative toolchain allowing developers to create native iOS applications using the Ruby programming language. Rich introduces the concept of bringing Ruby into the realm of iOS development, which previously relied heavily on Objective-C and Swift.

Key points discussed include:

  • Why RubyMotion?

    • Emphasizes the extensive ecosystem with over 400 million iOS devices available and the potential for creating apps that could be monetized.
    • The first app created in RubyMotion, Everclip, successfully launched and showcased RubyMotion’s capabilities.
  • Technical Overview of RubyMotion:

    • RubyMotion is a complete implementation of Ruby 1.9, statically compiled for performance.
    • Eliminates 'eval', but retains much dynamic functionality.
    • Built on the same runtime as Objective-C, allowing direct access to Objective-C APIs.
  • Toolchain and Compilation Process:

    • Utilizes LLVM for compiling Ruby code into native machine code.
    • The development process involves using Rake for building and managing projects, which simplifies interaction with the toolchain.
    • Provides debugging support and easy testing methods integrated within the framework.
  • Community and Libraries:

    • Over 500 RubyMotion projects already exist on GitHub, showcasing community engagement.
    • Integration with CocoaPods, enabling the use of Objective-C libraries within RubyMotion projects.
    • Discusses various libraries such as Teacup and Bubble Wrap which simplify UI and network operations.
  • Testing Framework:

    • RubyMotion includes a built-in testing framework that allows writing tests in Ruby, enhancing developer experience compared to traditional Objective-C testing methods.
  • Workflow in Popular IDEs:

    • RubyMotion projects can be worked on in various text editors including RubyMine, which supports command completion for native APIs.

Rich concludes by affirming the potential of RubyMotion to streamline iOS application development, leveraging the strengths of Ruby while allowing for robust app creation. He also highlights the importance of community contributions and the ongoing development of the RubyMotion toolchain.

Inside RubyMotion
Rich Kilmer • Denver, Colorado • Talk

Date: November 01, 2012
Published: March 19, 2013
Announced: unknown

RubyMotion is a relatively new toolchain for iOS development using Ruby. With RubyMotion, developers can finally write full-fledged native iPhone or iPad apps in Ruby, the language you all know and love. In this session, we will cover how RubyMotion works, we will talk about its internals and what makes it unique, and we will show how easy it is to write an iOS app with it.

RubyConf 2012

00:00:15.120 this is the ruby motion talk if you had any questions on what this talk was about it's about ruby in your pocket
00:00:20.880 if it's an ipad it probably won't fit in your pocket but it is about ruby in your pocket i am not laurent
00:00:26.640 sansanity uh who is going to originally give this talk laurent is the creator of ruby
00:00:32.079 motion unfortunately due to flights not going through new york was not able to get here
00:00:38.800 i am rich komer i've been to every ruby conf and i've been to every rails comp that
00:00:44.879 just demonstrates how little life i've had for a very long time um i was founder of info ether and the
00:00:50.960 ceo of that company was acquired by living social about 18 months ago and i've been at livingsocial ever since
00:00:56.800 and i'm actually an advisor to hip bite hip bite is the producer of ruby motion laurent works for hip bite
00:01:03.520 and i am wearing white pants today so this is a website that says is rich
00:01:08.960 kimber wearing white pants i did not make this website but it does track whether i'm wearing white pants or not
00:01:14.000 and today i am just so you know and if you're really bored right you can you
00:01:19.280 can go look there so this talk is about ruby motion and
00:01:24.720 uh you know ruby motion you know the question is why to write
00:01:29.920 this why was it important to write ruby and use the ruby language to run on an
00:01:37.759 ios device well probably the most important thing is numbers
00:01:43.360 there's 400 million ios devices out there right now there's 435 million itunes accounts
00:01:49.759 with credit cards behind them right now actually that was in june so there's more than that now that is a
00:01:55.280 staggeringly large number of devices out there and of accounts
00:02:00.399 for making things so one of the reasons to do this was because it's a very very large ecosystem
00:02:07.439 out there a large number of devices exist that this can be used on
00:02:12.959 and um but the question is can you use this to build apps that actually run within this
00:02:19.760 environment within the store the first app ever written in ruby motion that was actually put on the app
00:02:25.520 store was called everclip let's let you actually get clips and and send them up to evernote
00:02:30.640 it was built completely in ruby motion it was compiled down and actually
00:02:36.879 uploaded into the app store it makes use of third-party objective-c libraries so this app makes use of
00:02:42.160 third-party libraries it won the evernote dev cup award um it was accepted into the app store
00:02:48.239 and it's for sale there so applications can actually make money written in ruby motion so this is
00:02:54.319 another reason to actually do it this talk is basically going to cover uh
00:02:59.760 you know these items explain what ruby motion is how it works
00:03:05.840 what the the tool chain is for it that you can continue to use your favorite editor when building
00:03:12.400 ruby motion projects and what the community looks like first off
00:03:19.200 ruby motion is a complete implementation of ruby 1.9
00:03:25.200 it's statically compiled so it's not an interpreter that runs inside your phone
00:03:30.799 you take your ruby code it statically compiles it down to machine code we'll talk about that and and then it
00:03:37.760 runs within your your phone as any objective c application would run inside your phone
00:03:43.360 there is no eval so it's ruby minus eval but all the other dynamic
00:03:50.400 aspects of ruby you can do you can do define method you can pass block to define method and actually
00:03:56.239 still do all the dynamic things you can override what methods do on numbers at run time and do stuff like that let's change what
00:04:02.959 add you know plus does on an integer you can do that sort of thing the same kind of wonderful things that we can do
00:04:08.000 with ruby we can do here so that the dynamism of ruby is maintained but
00:04:14.480 eval is not there specifically because apple doesn't let you ship an interpreter or a i should say a
00:04:20.799 compiler inside your app on the phone right so these are compiled using your mac
00:04:27.120 and then it's compiled down and actually targeted to your phone
00:04:32.320 this actually is interacting with apple's tools so the tool chain is actually leveraging
00:04:37.440 apple's tools underneath to compile and produce this so let's talk a little bit about the
00:04:43.759 runtime this runtime the ruby motion run time is
00:04:49.199 exactly the objective c runtime there is no other runtime when you take
00:04:54.720 an objective c source file and you compile it that com that compiles down to code that runs on the objective-c runtime
00:05:00.960 which is built on the foundation framework and the ios sdk ruby motion compiles your ruby code down
00:05:07.280 to work on the exact same runtime it's a unified run time there's been
00:05:12.320 other products out there that have uh used a bridge technique
00:05:18.400 to take a you know one run time say a javascript runtime and let you develop ios applications in
00:05:25.600 javascript that are native right but those
00:05:30.639 techniques are basically having two runtimes running at the same time and they're bridging between the two run
00:05:37.280 times objects exist on both sides of that bridge and you have to maintain them the problem there is that it takes more
00:05:45.520 resources to do that it's not going to be as fast whatever they've implemented across the bridge is
00:05:50.800 what you can do right if they haven't implemented or exposed something across that bridge you
00:05:56.639 can't actually get to it so because we're sitting on the same run time you can do
00:06:02.080 everything that you can do with objective-c in ruby motion
00:06:08.319 the um there is a small ruby layer and i say small it's about it's
00:06:14.080 less than a meg that adds behaviors to the objects to give you for example the behaviors we
00:06:20.479 expect in string and kernel those things need to exist because that's our ruby code right we
00:06:25.759 want kernel we want modules modules don't exist in the objective-c runtime
00:06:30.880 so there is this layer not it's not a layer it is an additional capability which is
00:06:35.919 brought into the objective-c runtime and it's run there to allow your ruby code to run and to feel like ruby code
00:06:41.919 when you're um you know you're looking at your inheritance hierarchy you see kernel there just as you always would
00:06:48.000 and so that layer is there but it's not a run time in that sense there is no bridge
00:06:56.319 so one of the most important aspects of this is one of the reasons we love ruby ruby is a very concise language
00:07:03.440 how many people started programming writing c code started writing z code how many
00:07:10.000 people then moved on to java code right lots of lots of java code right java is one of those
00:07:16.639 languages in c and a lot of these languages and realize objective c is c with objects it was a branch of of
00:07:22.960 c that went off in one direction when c plus plus kind of went off in another direction and it added objects almost a small talk
00:07:29.759 like object structure to c but objective c is c when you loop
00:07:35.120 in objective c it's a c loop right so objective c is c plus objects ruby is
00:07:42.080 a purely object oriented language when you loop in ruby you can use iterators you can use everything that you're you're used to in ruby it's a very nice
00:07:48.720 high level very concise language this is hello world in ruby
00:07:53.919 that when compiled down in ruby motion would actually implement a class that
00:07:59.280 initializes with what you want to say and when you said to say that it would say hello
00:08:05.199 this is a comparable class in objective c you've got a header file here that declares it you you create a class an implementation
00:08:12.479 of it you implement a method that says hello um so if you look at that
00:08:17.599 it ends up that objective c is roughly three times the amount of code that a comparable ruby motion
00:08:23.520 file would be so it's about 3x or one-third the lines of code um
00:08:28.960 basically can go away just from a line count now that doesn't mean that you're not dealing with the same frameworks
00:08:34.959 you're dealing with the same frameworks that objective-c is it's the same frameworks that are on the phone on your ipad it's the same thing as a
00:08:41.440 matter of fact you can code i'm sorry if you can't see this from the back but you can code here this is actually
00:08:47.680 talking to opengl you can code directly to the c libraries so this is ruby code
00:08:55.360 calling c libraries including constants so all the constants available in c are
00:09:00.640 available in ruby as constants all the functions available in c are available to ruby and you can
00:09:06.480 call them this is a hundred percent of the objective c and c api are brought up into ruby to be able
00:09:13.279 to do this so let's talk a little bit about how this actually happens
00:09:20.000 in the compiler the compiler is based on um llvm so the technology used here is
00:09:27.360 the llvm technology to compile it down the ruby code down to native code and it's compiled ahead
00:09:34.320 of time it's compiled on your desktop computer to target the phone or to target the simulator that runs within your computer
00:09:40.240 and it's compiled down to a single executable you don't load things dynamically at runtime like you do with
00:09:45.600 ruby like we have the shared libraries and everything we don't do that here it's all statically compiled down to an app
00:09:50.880 an ipa file that actually is loaded onto your device and run so
00:09:57.440 you start with your ruby code and it produces machine code and the steps for that the first step is
00:10:04.079 we've got our ruby source code so we've got our class here hello view subclasses ui view
00:10:10.160 so if anyone by the way how many people here have done uh you know ios development yeah
00:10:17.600 how many people and it's fine if you do but love objective c as a language
00:10:22.640 right so it's cool no i mean it's fine i mean it's there's nothing wrong with loving it
00:10:28.320 because it's it's a tool that you have right and what sucks is having to work in a tool
00:10:33.839 that you don't love now how many people here love ruby
00:10:39.200 right see that's the thing so right compilation steps so we write in this
00:10:44.560 beautiful language that we've grown to love the first step is to parse this into an abstract syntax tree
00:10:50.160 so this is the syntax tree that's being part that's parsed into this is similar to what ruby does internally
00:10:55.920 when ruby's parser runs in your code on your desktop computer it forms an ast the next thing it does
00:11:03.200 though is it compiles it down into it the what's called the llvm intermediate language um it's
00:11:10.399 this internal language that's basically a portable assembly language that llvm has developed that project
00:11:18.320 and it's a place where you can actually apply optimizations to the code so at this step there's all kinds of
00:11:25.440 optimizations and by the way the llvm team has created a whole series of optimizations
00:11:31.600 reorganizing code removing dead code that you don't reach right it can do a lot of those things
00:11:38.240 hipbyte is actually created a whole series of optimizations for the ruby language itself as part of
00:11:44.000 this compilation process things like instant variable access speed increases so
00:11:49.279 accessing instance variables instead of just looking them up in a hash or something like that how do you do that incredibly fast
00:11:54.800 because we access instance variables in our classes all the time so how do you do that and how do you achieve dynamism without
00:12:02.959 sacrificing speed so you know how do you cache that how do you cache methods that you're calling and things
00:12:09.120 like that even though that method could be a different method in the future because you wrote define method and it replaced the method
00:12:14.320 so a lot of those optimizations are optimizations are built in as part of the compilation step and
00:12:21.839 and then it goes down to assembly language so at this point the assembly language produced here is
00:12:27.839 very similar to what your and you know ultimately the assembly language is machine language but it's
00:12:34.160 it's it's brought down exactly like the objective-c compiler is has you know compiled your your
00:12:39.760 objective c code your c code down through um the whole tool chain gcc
00:12:45.279 down to us to machine code and it's not going to look exactly like an objective c compiler
00:12:50.959 output obviously because one is ruby code and the other one is objective-c but whenever you
00:12:56.320 actually uh you know create classes it's using the same um the same methods available in the
00:13:03.120 objective-c runtime to create a class to create a ruby class as it is to create an objective c class because they're really one
00:13:08.399 type of class as a matter of fact every ruby class is an objective c class every objective c class is a ruby
00:13:13.440 class they're the same which is really fantastic this was an
00:13:18.720 example application that laurent actually built called mustachio that lets you take a picture and it puts a mustache on
00:13:25.120 the face but it's no longer in the app store but he put it up in the app store but the main thing to look at here
00:13:31.440 is the size of that application is 0.9 meg so just to show that this compiled
00:13:36.720 application which was an app that was released and actually accepted in the app store that put a mustache on on a baby's face was was less than a meg
00:13:45.519 it's not a very big run time to be able to support this application and you know this is important because
00:13:52.320 applications over i think 14 meg still don't allow you to install over 3g i don't i think it's still the case
00:13:58.320 and it may depend on the carrier but there is definitely a limit that says any app over a certain size you have to
00:14:03.680 install over wi-fi um or sync right you you can't install over 3g so having a small um you know additional
00:14:11.279 library size that ruby motion brings is really not going to prevent you from building robust applications with this so let's
00:14:19.120 talk a little bit about the tool chain and how the tool chain actually compiles
00:14:25.199 and produces the applications that we're talking about first the entire tool chain is based on
00:14:32.399 rake you do it from the command line so when you're running your application or
00:14:38.160 when you're building your application you do it with rake you just type rake matter of fact rake dash t to actually get the list of tasks
00:14:45.040 that you can do with your rate command to access the tool chain um from rake
00:14:50.320 you can produce an ipa on an application file that runs in the simulator local within your
00:14:55.680 your machine or you can say rake device to actually put it on the device or you can say you know rake archive to
00:15:03.279 produce i archives for the app store so everything is available directly from the command line
00:15:09.279 from rake you don't have to be inside of xcode and go into your targets and various
00:15:15.279 things like that and figure out how to do that you just type rake as a matter of fact if you have your device tethered to your mac
00:15:21.760 and you type rake device the app pops up on your device if you just type rake pops up on your simulator it's very nice
00:15:29.040 and i'll show you some of the specific things you can do while it's running in the simulator which you literally can't do anywhere
00:15:34.399 else other than this another feature that has been
00:15:39.519 implemented recently is full debugging support so this compiler of ruby down to native
00:15:48.000 code actually produces a dwarf file which is a standard file format for debuggers to
00:15:54.079 use when debugging your application like gdb what that means is you can attach to the
00:16:01.279 simulator running your app and you can set breakpoints in your ruby code
00:16:06.880 and you can get to backtraces and local and instance variables right from within gdb so this is just an
00:16:13.440 example of gdb running um you you start it up you have the b there in gdb break point
00:16:20.160 timer controller rb colon 32 and then it runs until it breaks at
00:16:25.519 timer controller 32 and so you see that come out um and you can and he checked uh the the
00:16:31.600 back trace there that's the bt command and you actually see the back trace as it was called through and if you notice the back trace all of those
00:16:38.639 are standard ios classes right that you're calling up through all
00:16:43.920 the way to the point where you're getting into your timer controller which is your class that you implemented
00:16:49.120 in in ruby motion so this debugger i'll show you uh tool
00:16:54.480 vendors will be able to use this to actually give you graphical debugging through an ide and there's one tool vendor is actually
00:17:00.399 already doing this it's about two weeks away from actually being able to release that which is pretty exciting
00:17:06.400 testing so i want the hands up of the number of people that have developed ios applications
00:17:13.919 okay how many people have written full tests for your ios applications right it's extremely hard to write tests
00:17:22.000 especially functional tests you might be able to get away with writing unit tests but even that could be kind of a pain even in objective c
00:17:28.799 but ruby is a very strong testing you know background i remember
00:17:34.320 all the way back to the first ruby comp that we had in florida um there there were
00:17:39.520 gosh probably five or six of the talks were on testing um uh even then and never said you know
00:17:45.440 is this the place that ruby's really going to take off is in testing because at the time no one was using it for anything production
00:17:51.280 so everyone was thinking well maybe ruby could come along and test things well so testing was very important and
00:17:57.919 hitbi felt it was very important to have testing kind of built into your apps so when you generate an application uh
00:18:03.919 with ruby motion you get a testing framework that comes with it it's an r-spec like language
00:18:09.520 it's it's a port of bacon and but it actually integrates with the run loop of ui kit
00:18:16.000 there's a there's a technology um within ios called ui automation which let you drive your ios
00:18:21.440 applications but the only way that you can and so this is kind of like functional testing
00:18:26.559 of a website where you're actually driving the website with functional tests what ui automation does is actually let
00:18:32.559 you do things like just send gestures to the device and taps and pinch
00:18:38.559 zoom and you know enter data and things like that in other words you can do full functional testing but if you're going to do this with
00:18:44.640 objective-c right now you have to write your tests in javascript because the only thing that apple surfaces with ui automation is
00:18:50.799 javascript-based testing with ruby motion your testing is in ruby
00:18:56.640 so describe the timer view controller test the timer controller um it has a timer label and it checks to
00:19:02.320 see that that there is a timer with that label so the view method there looks up a view
00:19:08.160 with that label and if it doesn't exist of course that test fails so it looks it up
00:19:13.760 and then you know it does a series of other things we'll actually run this test in a couple of minutes we get into the demonstration
00:19:18.960 but you can see there that it's getting the label it's saying the text to f should be zero
00:19:25.280 um there's there should be uh you know it should equal zero and then you tap start
00:19:30.880 um you wait a second and then you tap stop and then the the text should be one because it's basically creating a little
00:19:36.960 counter and it's checking to make sure that that text is changing because that's what your program does
00:19:42.240 but it's actually driving the application in your simulator and you're doing this with ruby code so the same language that you're using
00:19:49.600 to write your ios application you can write your tests in which is what we do when we do rails development or do any other type of ruby
00:19:56.240 development we love to actually write our tests in ruby because ruby is a very flexible language for doing this type of thing
00:20:02.880 i mean being able to do tap proper weight tap you know getting the the different aspects of
00:20:08.080 these things like you know looking up views those are dsl is an overused word but
00:20:13.520 it ruby's flexibility and its syntax gives us very very concise code and it's very
00:20:18.880 readable code of exactly what this does so so testing is actually built in to
00:20:25.520 every ruby motion project and you can do not only unit testing which you can do but you can also do functional testing
00:20:31.360 write specs to do that ah
00:20:36.400 ruby motion doesn't support xcode mainly because exo kind of sucks right and it is
00:20:43.440 it is it is really not the best editor in the world it's just not um now so for the last six
00:20:50.320 weeks i've been developing a windows 8 application for our company got it in the app store it's on you know
00:20:57.360 running on surface today and but i've forgotten so i i used to use um
00:21:03.919 intellij's idea um you know it which is awesome editor for java back
00:21:09.120 when i was doing java development it was just amazing um you know once i got into that editor i was like this is amazing and ruby code
00:21:14.640 i've never really needed that but as our projects grow more and more complicated the ide becomes actually
00:21:21.200 um more missed well having to do a windows 8 app which i by the way i did it all in javascript
00:21:27.679 but i was using visual studio visual studio for whatever it costs which is enormous amounts of money
00:21:34.320 is an amazingly good ide you compare visual studio to this this is like night and day different
00:21:40.080 right microsoft has hundreds of people working in their tools division developing tools that's why corporations
00:21:46.880 buy them apple doesn't have that same investment in this team i can guarantee that the
00:21:52.159 number of people that work in here is dwarfed by the number of people that works on microsoft tool division
00:21:57.280 um and so it's kind of why uh it's not supported is because it's
00:22:02.480 just not a really good editor instead the idea is to use the editors you use now if you use vim or emacs use it
00:22:10.720 continue to use that sublime text mate whatever you want to use to edit your files um i'm actually going to show a couple
00:22:17.440 of things so have people here use ruby mine right and i've kind of gone back and
00:22:25.600 forth right i used text mate because david hansen introduced me to text mate but um but you know text mate uh really what
00:22:33.120 you know coming from something that didn't even do syntax highlighting just had something that did syntax highlighting was fantastic
00:22:38.400 right so when when i got textmate and i was doing ruby development way before textmate came out um it was a great step um i go back and
00:22:46.400 forth i'm you know i'm trying to figure out which one between uh textmate and sublime that i like and kind of go back
00:22:51.600 and forth between them ruby mine was something that i hadn't really used much
00:22:57.600 um in my ruby development and i've tried you know on a couple of rails projects to do it and some personal projects i
00:23:02.960 was working on i kind of did it but about i guess it was around three weeks ago now
00:23:08.799 jetbrains came out with ruby mine eap and it's the earlier early evaluation
00:23:15.200 program for ruby mine and it adds the ability to build ruby motion projects so you can actually
00:23:23.200 create ruby motion projects and i'll show that in a second but importantly
00:23:28.480 you can get command completion through the entire ios api from ruby motion from within the editor
00:23:35.760 including of course your own methods that you're defining here so it gives you command completion with documentation
00:23:42.080 um so you can actually you know get the commands complete them out because if people know
00:23:47.919 this api this is an extremely verbose api so being able to just have this alone is
00:23:53.679 tremendous and uh you know as a very early user
00:23:58.720 of ruby motion like very early user of ruby motion having to go look up the apis and then
00:24:05.440 typing them into my text mate editor and then going and looking up the apis i was doing it right because it was still fun
00:24:10.640 to do and i was doing it in ruby this has helped tremendously just in the last few weeks that i've been using it
00:24:17.440 you know let me just you know it just continues down to be able to do it so this is coming
00:24:22.880 soon you might not be able to see this much but i just got this screenshot sent to me from laurent
00:24:28.880 he just got it today so this is ruby mine integrating with the debugging support
00:24:34.159 so if you can see what's going on here i'll walk all the way down here and point because i don't have a pointer a break
00:24:39.600 point was set at this line of your ruby code and the break point fired here
00:24:46.000 and these are the actual variables which are in the locals of this method right here so this is
00:24:52.880 real debugger support and if you notice this call sequence this is the actual
00:24:58.480 c-based call sequence so this is the compiled call sequence but layered in here you see this ruby
00:25:06.320 method inside this controller and this ruby method so it actually annotates the ruby methods and the c method so you see
00:25:12.640 them mixed in right because you're going to be bouncing back and forth between the objective c you know i
00:25:19.039 should say the you know the core sdk you're going to be going between those built-in methods
00:25:24.080 and your own and this lets you actually see what line of ruby code that you executed through
00:25:29.919 on the way to the one that you set that break point at what your locals were and they're going to be able to expose
00:25:37.120 you know the full kind of goodness of a debugger with ruby
00:25:43.039 and by the way you can do this while that app is running on your simulator on your device
00:25:48.159 on on your computer so when you set your breakpoint you're introspecting what's happening in that simulator in real time a little bit
00:25:56.400 about the community um so this came out about six months ago may 4th and
00:26:04.240 there are over 500 projects on github already around ruby motion 500
00:26:12.960 ruby motion allows you to integrate with something called cocoapods and cocoapods are a way of packaging
00:26:20.240 objective-c libraries actually see in objective-c libraries um for use on mac
00:26:25.679 and ios so it's both for mac and ios um but people are loving it for ios and so cocoapods and
00:26:31.440 what's really great is cocoapods itself is written in ruby and it's actually a gem so you say gem install cocoapods and then you've got
00:26:37.600 that um but within your rake file you can actually just include pods
00:26:43.600 so you require cocoapods and then you can include pods and there are over 600 of them so these are these are libraries that
00:26:50.080 have been when you when you install a pod just like when you install a gem on ruby it compiles it right
00:26:56.159 these pods will come down and build on your machine so they get downloaded um and they're
00:27:01.840 built on your machine and then you include the pod in your code and now you can reference all those classes
00:27:07.360 the same classes that are in there or the c functions that are in that pod you can access from your ruby code
00:27:13.120 so now if you want to use the uh you know the the facebook library or you know name
00:27:18.159 your library that's out there that you want to integrate with the native library you can just use it so we don't
00:27:23.360 we can go back and forth between you know do we need to write stuff in c or or objective c or ruby motion
00:27:30.559 but here you don't have to necessarily make that choice they'll actually work really well together
00:27:35.600 another really big thing that has happened and this is the thing that excites me probably the most out of this is
00:27:42.880 i mean ruby motion is amazing in that it is compiling your ruby code down to
00:27:48.159 native code this is not another ruby interpreter this is a compiler
00:27:54.240 but ruby as a language is an amazingly flexible language i said that earlier if you look at rails
00:28:01.760 and you've looked at all the clones of people that have tried to clone rails into other languages right and you've seen i mean they've got
00:28:08.159 all kinds of things that people have tempted to do mvc frameworks that mirror it rails is not a dsl
00:28:16.399 rails is a series of them that are focused on different areas inside your
00:28:21.840 rails application your migrations right you write migrations and rails and you look at them
00:28:27.039 those migrations is a language inside of there to write migrations it's the same with your route your route
00:28:32.320 file is actually a pure dsl in the sense that um you know now it actually does um
00:28:37.760 crazy implicit things with blocks that they never used to do before but they do now um you know but your route file is a dsl active record
00:28:46.399 um is a kind of class-based dsl where you've you know you're inheriting from active record base but you've got your code looks very
00:28:52.960 declarative and i would say that um you know the the um
00:28:58.240 you know the main thing about that is that declarative stuff at the top of your file where you're defining your associations
00:29:04.000 um and things like that um that's the part of it that this is so powerful and ruby because you can go bounce back and forth
00:29:10.000 you can use kind of hash syntax you can use parens where they make sense or not use them all of that flexibility in ruby syntax
00:29:16.799 makes it very nice when you're building abstractions so let's look at a couple of libraries that have come out
00:29:22.960 that are on github that you can build abstractions with this first one is called teacup and um
00:29:29.120 teacup the top part of this teacup thing is allowing you to find a style sheet using ruby code to just define these
00:29:35.360 styles and and then down below i'm building a ui view controller and i'm declaring a style sheet that i'm
00:29:42.000 going to use and then i build a layout in a layout called root and i'm adding a
00:29:48.080 sub view which is a text field that is going to inherit from the style that i defined in my style sheet
00:29:53.520 this is just a temp from this library author to build some kind of separation between the uh you know your
00:30:00.720 your you know how you lay out your components from the from the uh adding of the components to the view
00:30:07.039 right just like in html you want to have the structure of your html dom is separated
00:30:12.399 from the look of your html dom from css to html right that that's why you try and do that you
00:30:18.240 want to separate the two this is an attempt to kind of do that it's interesting right and this is and there's a lot of these
00:30:23.600 things happening matt m and eddie started a project called bubble wrap probably one of the most um used actual
00:30:30.559 abstraction libraries that's out there right now it wraps network access so look at this
00:30:36.399 http post so i'm posting a payload data out and it's just a hash now that hash
00:30:42.480 by the way is a ns mutable dictionary you do open curly brace
00:30:47.679 key value key value that's a hash it's also an ns mutable dictionary um when you build an array it's an ns
00:30:53.520 mutable array those are types within objective c right they're in foundation
00:30:59.039 and this is built right on top of them so it's a unified type system so here he's just posting things gets a
00:31:04.640 response back is a response okay um then he's parsing it so he easily parses jason out
00:31:10.559 and actually gets to the data that's inside of there but it's not just networks it's json xml
00:31:16.480 camera and location support there's a whole bunch of stuff built into bubble wrap they've looked at the
00:31:21.519 things that are if you will the really annoying common things that people do they want to talk to the network
00:31:27.120 they want to do json type data access and a lot of this is just people scratching niches right this is why
00:31:32.159 people build these libraries this one is absolutely fascinating how many people
00:31:38.000 here have had to build a form on ios this is a nightmare in objective c
00:31:45.200 you build a table view you build table cells as classes for each one of those rows
00:31:52.880 here you define basically your sections it's just a hash
00:31:58.559 so that thing on the left is a hash that generates that form on the right
00:32:04.720 and all of those things all those types at the bottom you can't really see it but it just says four motion form controller alec and it
00:32:11.039 with form and you pass that formotion form and it will actually build that view for you
00:32:17.200 and you could set data into it and get data out of it as keys and values amazingly simple to
00:32:23.919 do that sort of thing and this is the stuff to me that is most exciting it is the ability of building
00:32:29.279 abstractions on top of it that utilize the power of the language we love to simplify
00:32:34.799 the horror that is underneath it right
00:32:40.080 so parse model so if people have used parse as a service parse model lets you easily integrate
00:32:45.840 with that service you can just declare your class post include the parse model model you set
00:32:51.120 your fields then you can build posts and save them and it's saving them to parse.com of course you can figure it
00:32:56.159 with your your keys and things like that this is a really fascinating one motion state machine it allows you to build a
00:33:02.559 finite state machine for view management so if you've ever built views that are responding to different kinds of things your code can get really nasty because
00:33:09.279 things are going through different states and you're changing your views to handle those states a state machine can be a really nice way
00:33:14.640 of doing that and if you look at the very bottom of this it says finite state machine dot win
00:33:20.880 awake state transition in background on notification so it integrates with the ns notification system
00:33:27.200 to actually let you change your state machine when you're notificat when it when things are actually coming
00:33:32.240 from the system so when the system is telling you that you are about to enter the background it can
00:33:37.679 actually change your state machine and maybe that kicks off saving data within your application or whatever you need to do
00:33:42.880 to do it so and by the way this is all built on lib dispatch um gcd so it's very efficient and
00:33:48.880 concurrent the way this is implemented so it's fully concurrent
00:33:54.080 so i'm going to go through and do a couple of demos real quick
00:33:59.760 i'm in a mirror mode here
00:34:07.440 so the first thing i'm going to do is in ruby mine i'm going to create a new project and i'm just going to call it ruby conf
00:34:14.639 and here is where i can actually say it's a ruby motion application say okay i'm going to pick the sdk by
00:34:20.960 the way if you do this make sure and pick a 193 or 19x sdk it uses this ruby sdk it gets all
00:34:29.520 these by the way from rvm it uses this sdk when it's i'm going to make this sorry i'm going
00:34:35.520 to change the font size in this but it uses the sdk to parse your code and to do syntax
00:34:40.720 highlighting and you want one 9 right not 187 because 187 doesn't have ruby 1 9's hash and text and things like
00:34:46.720 that so i'm going to go ahead and build this
00:34:52.079 did i do that there it comes
00:34:58.960 it's doing its thing and while it's doing that i will adjust the size of the monitor make it
00:35:05.040 get bigger um it might be kind of hard to see here but
00:35:10.720 what i wanted to show is the structure of this application the the file that the main file that
00:35:16.160 gets generated for you is let's see if ruby mine lets you no you can't zoom this way
00:35:21.440 easily anyone know how to quickly zoom in ruby mine oh do that thing there you go all right
00:35:29.680 so um the main class is your main entry point into your application is your app delegate and if you look in here um you're
00:35:36.720 implementing a class that implements application did finish launching with options
00:35:42.400 this code right here did finish launching with options colon that in a method definition if you look at that let me zoom out just
00:35:49.680 a little bit so you can see that method declaration this method is not a valid
00:35:55.040 ruby method there is no ruby method where you actually can set a key and value
00:36:01.520 in the params that you're passing in right that's not what ruby does and this
00:36:07.839 was actually added as part of the ruby syntax for the mac ruby project and this carries over into this because
00:36:14.720 in objective c the selector the method you choose is actually based on the series of concatenated param names
00:36:21.599 so the app the the actual method name is application colon did finish launching with options colon
00:36:27.920 that's the selector that's the method but in ruby there's no easy way to define a method like that
00:36:33.280 because our methods have very simple little names so the syntax was added so that you can have this kind of hash syntax matter of
00:36:39.520 fact it is hash syntax and it interprets that as your full method declaration
00:36:44.640 so this allows you to actually implement methods that can it's easy to call methods that way but to actually define methods
00:36:52.960 uh this is our rake file so our rake file says the app name is ruby comp uh what's nice here is i can run this
00:36:59.680 app in the simulator so i'm right here within this tool and you see there at the bottom of the
00:37:05.599 screen that it's running simulator comes up
00:37:11.359 and the app is there now you don't see anything because it's not doing anything it didn't create a window
00:37:17.680 or anything like that but i just wanted to show you that you know it's very simple to create
00:37:23.760 an application by the way um quit out of that i'm going to show you a little bit more of what you can do
00:37:30.320 this is your spec that actually starts if i was to run that spec file it would fail because right here it says
00:37:36.560 i'm going to create get an application i'm going to make sure the windows has a size greater than one that a window is defined there isn't one
00:37:42.079 so by default your specs fail yay testing um right because that's the way we
00:37:48.000 should be doing test driven development so this is an example that comes with it and by the way um
00:37:53.920 up on github there's ruby motion samples and these samples there are um hold on there are a whole
00:38:02.400 series of examples out here i'm going to actually use the timer example and i'm just going to type first rake
00:38:07.680 dash t and rake dash d gives us the list of um the list of tasks we have
00:38:15.119 so these are how you interact with the tool chain rake if i do rake simulator or just rake
00:38:21.599 it actually runs the app on the simulator if i do rake
00:38:26.640 so you see rate config this shows you all of the different
00:38:32.000 things that you can actually set on your application this is literally everything that you can do to define uh parameters on your
00:38:38.160 application you can set all these in your rake file by default there these are all the defaults so it says the default frameworks you're using
00:38:44.640 so if you're using a different framework you just add that list you know that framework to the list of frameworks that you're supporting
00:38:51.040 what interface orientations all these sort of things are available to you to actually override in your rake file
00:38:56.160 but these are the defaults so if i just type rake simulator is going to come up and this
00:39:02.079 timer is going to come up now there's a couple interesting things that you can do here the first thing is
00:39:07.440 i'm going to make it so that i can see if i can both of these at the same time first i
00:39:13.760 can do this now what's really cool about that is i said one plus one or one plus two equals three that looks
00:39:20.880 like irb right that code is being dynamically compiled injected into the simulator
00:39:25.920 run and actually brought back his output to your command line
00:39:31.359 which is pretty amazing right what's even better is you know you output self and you've got main
00:39:38.320 now watch this little trick boom that's the ui label self is a ui label
00:39:45.440 self.text self dot tech text equals hello
00:39:54.720 so i'm actually able to adjust what self is by using
00:40:00.960 the command and my pointer over the simulator to highlight the ui widget that i want to introspect
00:40:06.480 and then i can actually start playing with the attributes of it if you've ever had to do that where you keep trying to just set the auto resizing mask to
00:40:12.800 figure out how something's supposed to work inside your ui you can now do this at that level and this could just get
00:40:19.760 better with ides actually doing this to where the code you're typing in there may be able to
00:40:25.119 um kind of in in real time be put back into your project or set the debugger
00:40:30.880 so that's interesting i'm going to run rake spec on this to run the the tests so this is going to compile
00:40:38.000 the spec it's going to relaunch the simulator and the simulator is running increases
00:40:44.560 the units so it's actually clicking the buttons and it all it all finished
00:40:50.240 so um if i look at that spec
00:40:58.079 so this is the spec that actually did that now this i know i can increase the size of
00:41:04.720 and it um it just ran the series of tests it accessed the thing
00:41:10.000 um it increased the number it waited uh you know click the buttons and i was able to write a test that
00:41:15.280 functionally tested my application that i built which is pretty cool so all of these um
00:41:20.800 these samples and by the way most of those 500 projects are samples and there's just a ton of samples that are out there
00:41:29.680 so that's a that's a quick demo of it um so thank you i mean this is actually the conclusion of the one thing i will say
00:41:36.160 real quick is right now and then through sunday there's a 20 discount buying this um for ruby conf
00:41:43.200 and uh which is a good savings if you want to actually try this out
00:41:48.400 um and there currently is no eval evaluation version of this application
00:41:53.599 it's like you buy it and you use it although um you know i mean hip bite is fair that if you really hate this thing
00:42:00.480 they'll refund you your money the main thing is um they're a small company that are doing awesomely great things
00:42:07.040 and they need to be able to support the people who are paying customers which is why right now there's no eval version although they may there may be
00:42:13.520 one at some point but um right now uh the 20 discount is actually pretty significant
00:42:19.040 especially considering what it does also um matt eminetti if you look at merbust
00:42:25.760 on twitter he has tweeted out that he has a discount on the book that is this macrobi book that book is
00:42:31.200 actually really good from the standpoint of mac ruby and ruby motion do a similar thing in that
00:42:36.880 mac ruby's targeted ios i'm sorry at os 10 and ruby motion has targeted ios
00:42:43.040 but a lot of the things that you learn from mac ruby you can actually use on ruby
00:42:48.160 motion especially when it comes to how it works with the objective-c runtime and things like that so look for that and if you search on
00:42:54.560 twitter for ruby motion or go to rubymotion.com you can get this discount today and with
00:42:59.680 that i am done
00:43:07.280 we have time we have time for a couple of questions if people yes really quick i'm curious why is the
00:43:14.000 mustache on the athlete laurent didn't renew his developer license and it they pulled it off yeah
00:43:21.680 because he that's how much he likes apple um yes what kind of limitations does it put on the ruby code that we can write can
00:43:28.400 we still have the alan you can't do eval eval is the thing you cannot do
00:43:34.079 but you can still use define method and things like that so all of the meta programming aspect of ruby is there just
00:43:39.119 not eval because you can't actually ship the compiler in the phone is it possible to integrate some of that
00:43:45.520 testing with the existing ios app repeat the question yeah i'm sorry so
00:43:51.119 the question was is it possible to integrate with an existing ios application um and build a kind of a hybrid
00:43:56.800 application for testing so so just use this to actually test your application
00:44:02.800 um not right now no um i mean you can use a lot of the code you've written
00:44:08.000 you know if you want to actually build something that ruby motion is kind of on top of but right now there's nothing which lets you kind of embed ruby motion within the application
00:44:14.400 that you've written in objective c yes do you know if the tcup library and
00:44:20.560 the form library are able to work with each other like our evil style forms i don't know about that but yes you can
00:44:28.960 so yes
00:44:34.800 so the question was can you debug with a tethered device instead of just a simulator the answer is no you can debug on the simulator um but
00:44:41.440 the actual device prevents you from actually making the kernel calls necessary in order to do that level of debugging
00:44:48.160 so uh just real quick here
00:44:55.200 that is the off most requested feature of this and uh and there's over 400 million ios
00:45:02.960 devices that you could start with right now um but uh it's it's
00:45:08.400 uh you know it er hitbite knows that it's actually something people really want and they're taking it very
00:45:13.839 seriously that's pretty much all i can say on that
00:45:24.800 right so that would be an advantage right so theirs is not freaking awesome would
00:45:31.359 be the disadvantage no i mean i i actually uh i would not write objective-c applications at this
00:45:37.599 point for ios period yes
00:45:49.599 well that's what i showed with the opengl example that code that was in that slide is actually calling c code so all the c
00:45:56.000 constants and all the c functions that are actually available on ios which is a lot of them are callable
00:46:02.319 directly from ruby you can include it that's what the cocoapods thing is but you can also include your own frameworks and you can
00:46:08.240 include them within your your app and ship them you had a question and then i'll come back here when
00:46:22.720 yeah don't just put it all in one file by the way you can do that but i wouldn't recommend it um but it is cool that you can actually
00:46:28.560 have all of your ruby code in one file but you obviously don't want to do that for scale right now you have to set the the order
00:46:34.480 in which things are compiled if it's order dependent like if something requires another thing before it when you're in your rake file you
00:46:40.240 actually say here's the files that i want to build but they're working on something which actually uses the compiler to actually
00:46:46.240 figure that out um as part of the compile step so you won't have to do that but right now you just in your rake file you just say
00:46:52.000 here's the 10 ruby files or the 15 ruby files and by the way i've done this on some of my projects i just say okay here's the ones that are really
00:46:58.000 kind of order matter and then glob the rest of it and then delete the stuff that's redundant so it's like a really short
00:47:03.599 little thing to actually get my list of ruby files so even the gems dependencies that are
00:47:09.040 you know coming out of their gym file so if you're um well i mean you're not using all your gems that you use in ruby
00:47:15.839 on this right i mean because some of those things are not i mean if you've had it
00:47:22.960 there's no required yeah there's no require i mean you can't use things that have require in them so for example cocoapods there's some
00:47:29.280 things that actually have code where you say require this code but that's actually being required in the rake task not being required in the run
00:47:35.440 time it it literally loads all the ruby code up and compiles it down
00:47:40.880 so what you're doing is you're defining what all that ruby code is that you're you know you're defining that space of ruby code in the order of that and
00:47:46.160 that's why it was important for very large as projects get larger that you're going to want to have something that does automatic dependency
00:47:51.520 resolution and they're looking at exactly how to do that and they're working on that but right now it's not too hard
00:47:57.440 until apps get tremendously large to maintain that but a lot of times it's literally just
00:48:03.280 i'm going to target these five directories and glob them up because you can use ruby to do that in your rake file
00:48:10.559 we only have time for a couple more questions but
00:48:18.480 the llvm static analysis tools do they work with this because this compile chain i mean that
00:48:24.400 you can plug into the process of it actually doing it like the actual compilation so i i
00:48:30.240 i don't think they they allow that right now i mean because this is you know it comes to you as an executable that happens to be built with llvm
00:48:37.520 um i don't think that they can plug into that process that i know of
00:48:47.440 can you use instruments on it um no i so the question was can you use instruments as part of this application and the
00:48:52.880 answer right now is no yeah one more because
00:49:05.680 well yeah so the question was because we're ruby's developers and we love open source um is there any way that we can contribute to this so there's
00:49:12.559 there's parts of the tool chain that actually are up on github and are open source and do accept pull requests and actually have people
00:49:18.480 actively doing that um but those 500 projects on github are people actively contributing to it
00:49:24.800 so you don't think as much of the run it's kind of like do how many times have i contributed to ruby itself as opposed
00:49:31.440 to building things on top of ruby nowadays i built things on top of ruby actually did contribute to ruby a long
00:49:36.559 time ago but most of the time we're thinking of building things on top that's where the community is working right now but there it has been especially in the
00:49:43.839 first six months some work on the lower parts and those things were open sourced um and you know they continue to do that
00:49:49.920 and all the samples are open source and things like that so all right thank you guys very much
00:50:27.200 you
Explore all talks recorded at RubyConf 2012
+46