 I think many of you have heard of Ruby Motion. It's Ruby that runs on the iOS, so you can finally do Ruby on your iPhone. Yay. So here to speak to us about that is Amit Kumar. He's from Mumbai, India. He lives in New York. And are we good to go, Michael? Sorry, we're making a technical adjustment here, so I will do a little soft shoot. I guess I'm supposed to do the, what is the Gangam style? That's enough of that. I'm not in five inch heels though, so I got it easier than Brittany. Okay, are we good to go? Great, so here's Amit. Thank you. Thank you. So here I am. It has been great in San Francisco, coming all the way from India, Mumbai. So thank you, San Francisco, and thank you, Josh. So I'm here to talk about Ruby raising iOS development, which is Ruby Motion. I have been doing Ruby Motion for just a couple of months, and I would like to share my experience, learnings, how I started getting into Ruby Motion, and what I have been doing so far. But before I do that, I would like to quickly introduce myself. I'm a Rubyist doing Ruby development for almost four or five years. A consultant at Tata Consultancy Services Limited, the company that manufactures cars. That's what I have been hearing from everyone. Whenever I say I work for Tata, oh, the company that manufactures cars. Well, Tata is a company that is into every business that you can think of. That's my GitHub handle, Twitter, and my blog post. So I would like to do a quick survey. How many of you in the crowd are Objective-C programmers and have done Objective-C next code? And keep your hands holding. And how many of you love Objective-C? Ha ha ha ha ha ha. Okay, so basically I can be safe. I'm not going to be killed. Because just a year before I started learning Objective-C, I thought of learning Objective-C and this is what I ended up. It's complicated. Yeah, everyone is talking about simplifying things. It was complicated, so I did not choose to go that route. And just in May this year, Laurent Sansonetti, he's a one-man army. He created Ruby Motion. It launched. I saw that, I liked it, kind of paid for it. It's a paid licensed product. I bought it, enjoyed it, and I'm enjoying it. I have built three apps so far. One of them is going to be on App Store pretty soon. Recently, the one-man army becomes two-man army. I joined by Watson. Watson is his handle on Twitter and other places. He's CISO from Zapan. So what is Ruby Motion and how Laurent defines Ruby Motion? So basically Laurent says that it's a revolutionary tool chain for building native IS applications using Ruby language. I define it as it's a neighbor's envy and code is delight, which brings happiness. So we'll see in the presentation the moments of happiness as a Ruby developer. Let's dive deep. What exactly is Ruby Motion? So Ruby Motion is a commercial folk of Mac Ruby, Ruby implementation of Mac OS X. It compiles into optimized machine code. So basically the source code of Ruby compiles into optimized version of machine code, which is converted into SMB language by LLVM. Laurent rewrote LLVM for Ruby Motion from Mac Ruby because it was a folk from Mac Ruby. It has automatic object memory allocation and reclaim, which is pretty cool. So that is the first moment of happiness because I'm not going to deal with memory allocation of objects and for objects and then releasing them. I don't have to worry about that. Ruby Motion is going to take care of it. I'm happy. Next aspect is it compiles the interface. So I'm sure everyone who has done a little bit of object to see or have heard about it, you know what is storyboards, what is Nibs. So basically you create interfaces and interface builder of Xcode. What Ruby Motion does is you create your interfaces in your interface builder of Xcode and kind of get that XML file in your Ruby Motion application and Ruby Motion takes care of compiling it. So that's pretty neat. That's the second moment of happiness because then I can design the interface in Xcode and still kind of important Ruby Motion application. Ruby Runtime is tightly integrated with Objective C Runtime. We'll get into it what exactly it means. One important aspect is it has the same ancestors as Objective C which means that all the classes that you have in Objective C, you can kind of use that directly in your Ruby application which is Ruby Motion. Let's look at an example. So what we see over here is in an array class, it's a blank array, and if we see the ancestors, the array is the Ruby Motion class or the Ruby class. The NSMutable array is the Objective C class and so on it goes all the way to kernel. So what we see is they share same ancestors which means that potentially you can use objects or share objects between your Ruby code and your Objective C code without any performance impact which is pretty neat. So essentially if you are building a Ruby Motion application you are actually building an Objective C application because at the end of it, it compiles into executables which you get as an output from your Objective C applications. There are differences here and then yes, we have seen that because Ruby Motion is pretty new. So let's look at architectural how it looks like. So what I've said that Ruby Motion and Objective C share the same runtime. They have the same ancestors which is the foundation framework and you can potentially call all the SDK APIs from your Ruby application which is kind of cool. When I started learning Ruby Motion, there was a few questions that I asked myself and I was asked by people around because that's what you have to answer questions. And I called them myths. So the first is, this question I was asked multiple times. Can I code in Ruby Motion without the pain of learning Cocoa Framework? I would request every one of you to answer that question. Is it possible to do that? Do you think it's possible? Exactly, that was my answer. No, it's not but rather I feel if you're coding in Ruby Motion, you are more close to the Cocoa Framework because as Ruby developers, we want to control things. By control, I mean not go and control everyone. By control, I mean you want to control, have a control on the code that you're writing. You don't believe in magic. You kind of, I would like to build my interface myself with code. So we look at it in one of the most powerful aspects of Ruby Motion. The second question I was asked, when there are frameworks like PhoneGap, if there are any, I didn't ask that question, are any of you lover of PhoneGap like frameworks? Okay. Yeah, so there are PhoneGap like tools which kind of does the same thing. Why should I care about learning Ruby Motion? My answer would be let's look at the pros and cons of PhoneGap. The first is it's very easy to use it. You potentially code it in HTML, CSS, and JavaScript and we all love that language, especially because JavaScript is the next big thing. Yeah, but there are a few disadvantages, especially because it's a bridge. And whenever you have a bridge, you always hit the performance bottleneck. And also, I don't know why, Apple is not optimizing UI WebView. PhoneGap uses UI WebView and it's a single thread model. So there is always a big performance bottleneck. It's one fourth of the performance that you will get in a native application. Another thing is you are basically limited to the support of PhoneGap if you have to use the native APIs. The most important aspect of using PhoneGap is debugging becomes extremely painful because what essentially PhoneGap does is it uses the native JS bridge that Apple gives you to kind of make native API calls of the SDK. So if you have to debug that, it becomes really difficult to do that. So how do I download Ruby Motion? As I said, it's a licensed product. You have to pay $200 and probably there is something. There's a surprise at the end of the session. So keep your eyes open. So you have to basically download it and to get the full featured version, you have to pay $200. But trust me, after paying that, I never regretted and probably you will not. So after you have downloaded and installed, one of the commands that you have to, which kind of kicks off here is the motion command where you have the four options. The first is the motion create, which helps you to create a vanilla application. The motion activate, which activates the license. It's pretty straightforward, updates, software, the support command, which is kind of very, very, very cool because what happens is from your console, you have access to the support ticket system of Ruby Motion. So basically you say motion support and it opens up the default browser on your machine. Probably it's always Chrome. And you have certain fields filled up already, which is your license key, the information about your machine. And then only thing that you'll have to fill in is the bug report that you're trying to file in or any feature request. There's one thing that you have to remember. One pro tip that I'll provide is, if you want to stick to a particular version, this is the command that you should always remember. Motion update will update to the latest version of the software, but if you want to stick to a particular version, you may have to use this. After you have created your first application, this is what it looks like. So you say motion create gogaruku. You have the rake file. You have the app delegate class, which is the point of delegation entering to the application. You have resources spec. We'll talk about it in the coming slides. Let's look at the motion rake command. So basically what exactly is, I'm sure every Ruby developer knows what is rake. In Ruby motion, your bread and butter is rake from the point of you developing an application to testing an application to deploy the application you will be using rake all the time. The starting point is going to the rake default command, which is kind of a command or just a rake command that basically builds your application and runs the application in the simulator. The second one is the rake spec command. You know what rake spec does. Ruby motion by default comes with a RSpec-like framework, which is called MacBacon, which has been there for a long time till the time, and what it does is it has all the flavors of RSpec, syntactic sugar that we have used in RSpec world. Rake build, which kind of just builds the application. Archive creates an IPA file which you can distribute or you can push it to App Store. This is something that, you know, there are other commands as well, but I'm not talking about it because as a new developer in Ruby motion, this is only that I'm concerned about how should I build the application, how should I test it and deploy it, that's all. There is one more command which is very, very important, which is rake config command. So every iOS application has a bunch of configuration options and this rake config command gives you or rather lists down all the configuration options that you have in the application. So let's look at them a little closely. I would let you digest. It has a lot of information here. The first one that you would be interested in, how should I name the application, which is the name of your application. You can change these configuration options in your rake file, which we saw when we created the, you know, motion create, go, go, go. The second option is the delegate class. App delegate is the entry point of delegation to your application. Then is the frameworks. There are a bunch of frameworks in Cocoa. The defaults are UIKit, foundation and core graphics. You can add more frameworks like core plot and any framework that you want to use in an application in an array in your rake file. The next option is the device family. It can be iPhone, iPad, or both, depending on what you want, or which platform you are trying to focus. There are other configuration options that, you know, I would like to talk about. There could be a, so basically what happens is in a Ruby motion application, when you fire rake, potentially what it does is starts compiling your Ruby source code. And when it compiles, it by default compiles in alphabetical order, which means that there could be a possibility that you have a class inheritance which does not kind of follow alphabetical order, which is like this, in this example. You have curves controller, which is dependent on main, which means that by default, Ruby motion is going to compile curves and then main, but it will fail because you have a dependency. So basically what you are doing is you are telling the compiler that dude, you have to compile main and then compile curves because there is a dependency change. There is another thing which is the vendor project, which basically helps you to use external libraries in your Ruby motion application, which is pretty neat because this is the latest addition in Ruby motion and I think this is really powerful because it helps you to kind of use external libraries which can be an object to see library as well. So you look into that in the coming slides. Now we have seen all the configuration options. So let's look at the soul of Ruby motion. That I call it soul because I loved it so much. I did not have any Objective C background or a Coco background when I started learning Ruby motion and the soul helped me to learn the Coco API mode, which is called REPL, re-evaluate print loop. So what I'm going to do is do a quick demo, taking that risk. Usually you should not be doing it, but I'm taking that risk because it will be much easier for me to kind of explain it to create the impact. So let's look at a demo. So what I have done is I have created a default application, which you have seen that. So if I list it, it's a Gogaruku application with default. I have a bundler dependency management injected already. We'll talk about it, how to use bundler. But for the demo purposes, I'm just going to fire up the application. So let's look at it. Right now what I have done is I have created a single controller with a blank view. And what I'm going to do is play with that view, add few controls and we'll see how we can control everything that you see on your simulator from your console. So it is building and the simulator is launched. Now you see that this is where you have the control. So let's grab the instance variable of the controller from console. So I'm using some syntactic sugar from bubble wrap, which is a Ruby motion gem. We'll talk about it in just a minute. Did I spell it wrong? I'm controlling my nerves. Thank you. If I do a mistake, I will run away. I hope everything is right. Yes. Thank you. Love you guys. So I have now handle of the controller now. So what I'm going to do is it has a view which is blank. Let's change the background color. Which color do you like? Blue, green, you guys. So I was able to change the color from the console, which is nice. So now what I want to do is I want a control to be added on the fly. Let's see. Let's create a control first, which is a segment control. UI segmented control. Controller nerves, no spelling mistakes. Okay, it accepts an array. Let's create two elements. Hello. Patient attendees. If everything is right, it should create an object. Ooh, it did not go there because I have not added. So let's add it to the view. So you can see that it's a Ruby syntax that I have been writing so far. I love it. Keep the fingers crossed. So I was able to add a control from command line, which is nice. Let's play with that. What I want to do is I would like to move it 200 pixels down and 100 pixel probably towards the right. Let's try that. I'm going to use another Ruby motion gem, which is sugar cube. And let's include that gem on the command line. All right, so the gem is loaded. And I want to adjust the view controller.view.subviews. So I have handle of that particular view now. Let's move it 200 pixels down. You'll have 200, 100, 250, I'll look at 200. So I was able to move it. That's nice. Let's move it 100 pixels towards the right. Perfect. No, it does not. I don't like it. So maybe you can. So you can basically continue playing with it. This is one way of playing with it. There is another way, which is really nice. If you just keep an eye on this particular object here, main, as I'm dragging what I'm holding, I'm holding the command key and I'm moving. And if you see it is null, but if you go it here, you can see that it changes to UI view because I'm hovering over UI view. I can move it here, which is a segment control again. This is nice. And if I click it, now you see that main has changed to the object that I have highlighted. See if I do self. Who am I? So can I change it? Self.label. No, I cannot. So I know that. Can I change it to something else? Everyone kind of love that. Yeah, I was able to change it. So hello, changes to Hela. Cool. There is one more syntactic sugar that I would like to show to you, which is if you are playing with this, you can see all the hierarchy of classes of the window, which starts from UI window and goes all the way to the segment label, which we change it over here. All right. So I was successful. Demo completed. Cool. So you feel in control. I feel in control. This is another moment of happiness. So what was the count again? There is an excellent thing you should check out, which is an in-browser demo of Ripple. Go to this particular link, and you should see two, three applications, and you can play with it. The build process. How does the build process happens? So it's a four-step build process. The first step is compiling. So when you fire Rake, or when I fired Rake in the demo, what essentially happens is all your Ruby code is being compiled into machine code, which later on converts into assembly language with LLVM. The second step is linking. What RubyMotion does is the machine code that was generated, it links them with RubyMotion statically. And then an executable is created. It is the same executable that you will get if you compile an Objective-C application. Kind of similar. Then what it does is it packages them, or it copies those executable files in your build directory of the application. And then beyond that, you have a full-durning compiled code. And it also, if you are archiving it, it will create an IPA file, which will be ready to push to App Store. There is the fourth optional step, which is code signing, which is not required when you are building or testing. It is required when you want to push it to App Store. Everyone would be interested in doing testing of your code. You definitely, everyone likes code testing, because that's what we do. We love Ruby because it helps us to test our code. So RubyMotion, by default, comes bundled with an aspect-like framework, which is called MacBacon. So when we created the application for the first time at the motion root, I call it motion root, because that's a root of your application, there is a spec directory, and it has a main underscore spec.rb file, which is a canary test. Everyone in this room understand what a canary test is, right? It's a default test that has nothing. It is an assertion that you are doing true is true. So it's kind of a test that is a starting point of your application, which says that your application is ready to be tested. More tests can be added to your application. So when you say a re-spec, should I take the risk of doing the demo again? OK, I'm taking the risk again. So let's look at the spec directory. There is a main spec.rb file, and let's open that. By the way, I did not mention there are a lot of IDs that support RubyMotion right now. So if you see that, this is what it testing. UI window, app.windows are size. That should be equal to one, which is always true. It's never going to fail. So I'm 100% confident it's going to pass, unless until my luck is really back today. So we will see that this simulator will launch again, because it runs the test case in that environment. That kind of gives me a break to take some more. Cool. So it passed, which we see at the bottom has one window, one specifications, one requirement, zero failures, zero errors. Nice. OK. So MacBacon has almost all the syntactic sugar that we are accustomed to in our spec framework, which is your assertions, matchers, your before and after block. The one other thing that I really like about MacBacon is that if you are building your interface in an interface builder of your Xcode, and if you want to test that, it gives a way to test your views as well, which is nice. So it basically loads the nib, zip, or storyboard file, whatever you may use in your application. While I was building application, because it was for a client where we cannot push the application to test flight, there was a need that we should be able to share our application internally and ask our client to test it, which required that we set up a continuous integration, something like this. So this is very simple. Essentially what it happens is the moment you check in the code, there is a webhook, which is hooked to your Jenkins server, which was on a Mac mini. The important aspect to observe over here is the push that happens from Jenkins server to an app store that we have created internally. And it uses deploy over-the-air technology of Apple. And it is kind of a P-list file that is created that helps you to download the application. If you browse to app store, you will see an install button, and you will be able to download the application on your device and then test it. So that was a kind of feedback loop that we were working with the client, and it has worked really well. External libraries. There are four ways to use external libraries in Ruby Motion. The first is RubyGems. The second is the Objective-C project itself. The third one is the native-C. So if you have any native-C application or library that you want to use in Ruby Motion, you can use it. And the fourth one is CocoaPods. Let's look at each of them individually. The first one is RubyGems. Normal RubyGems won't work. That's a bummer. And why it won't work? Because RubyMotion is statically compiled. And so normal RubyGems of MRI is not going to work on RubyGems. RubyMotionGems have to basically extend the configuration file. And the authors of RubyMotionGems have to take care of loading the files in Motion Project app block so that RubyMotion compiler knows that this particular gem has to be statically compiled and injected as the dependency inside the application. If you have few gems, then definitely Bundler is a default. And you set up Bundler, which is pretty straightforward. You create a gem file. And then you basically require Bundler in your rake file because rake file is the entry point of launching your application. So then, yeah, this is very important. RubyMotion has been accepted by the community. And I think there has been a lot of contributions from the community. And I would like to list a few of the gems. Bubblewrap is at the top. People love it. It's kind of helpers which reduces the verbosity of Objective-C code. There is another one, which is T-Cup. I use SugarCube. T-Cup is a style sheet. It helps you to kind of move away from building the interface from code. You can have style sheet way of presenting or creating the views. And then we have SugarCube. We have FarMotion. The last two are the one that I created and contributed back using Objective-C code. There are two ways to use Objective-C code, by the way. The first one is the statically compiled. And the second one is when you are doing a statically compiled, you basically include that particular directly in your vendor project of your application and declare it as static so that the compiler knows that it has to be compiled. The second one is including the Xcode project itself. So if you have a working Xcode project, which is an Objective-C library that you want to hook in your application, similar in concept as engines in Rails world, you can do that. And beyond that, it becomes part of your application. Using native-C code. The basic types in C are basically a map to all the Ruby data types. We all know that. But complex data structures in C, they don't have a corresponding Ruby data type. So essentially, what you end up doing is using bridge support in Ruby motion. By default, the latest version or other line comes with bridge support. And you don't have to compile it. The next option is the Cocoa parts. It's a dependency manager of Objective-C projects. And it's a Ruby gem. You essentially just do a gem install Cocoa parts. And then you do a part setup. Well, part setup, I had to do it. Maybe you may not have to do it because my machine never worked without part setup. This is a list of all the parts that you can play with. And then you have to install a motion Cocoa parts gem for your Ruby motion application. And then you have to declare the dependency as we see in the screen. If you want to use JSON, Git, Objective-C library, then you have to declare dependency in the rake file. So the four ways that you can use external libraries in your Ruby motion application. It has a long way to go. The Ruby motion is just four months old, approximately. There's something that it lacks. It lacks debugger. But Ripple is a nice way to know maybe you don't need debugger. I kind of feel that debugger is required. Some of the dynamic code may not work. And actually it doesn't work, but hey, who cares? Ruby motion application is an app store. EverClip was the first one. Cabify is the second one. There are others that are coming up. The third one, the order messed up. Survey is something that I'm going to push the app store pretty soon. And thank you. So one more thing, which is a 15% discount. So if you want to play with Ruby motion, just shoot me an email and you'll get that discount of 15%. Cool. Thank you very much. Thank you. Great.