Developers interested in native iOS app development have been restricted to the limits of Objective-C and Xcode—until RubyMotion came along. RubyMotion enables you do full iOS development using Ruby. You have access to familiar tools such as Rake and RubyGems and can compile Ruby code into native applications. RubyMotion even comes with a Ruby console useful for live coding and interactive debugging. And since RubyMotion is built on top of the Objective-C runtime, you can use all of Apple’s libraries and most third-party code alongside Ruby classes.
This book takes you from zero knowledge of iOS development to building an app that displays information about colors using a web service API. You’ll work through each topic with a small example app that covers just enough to get you familiar with the techniques you need to get real work done.
You’ll start with just drawing boxes on the screen, but you’ll quickly add animations, a navigation stack, and high-performance table views. You’ll peek into less visibile components, such as using Ruby metaprogramming to create JSON-based models. You’ll use some incredibly useful common Ruby techniques that are only possible in RubyMotion, such as writing automated unit tests with an RSpec-like framework.
Using both Apple’s existing libraries and fresh, community-driven RubyMotion projects, you’ll be well on your way to writing real-world apps.
What You Need:
A Macintosh running OS X 10.7 or later is required to install RubyMotion. Experience with the Ruby language and Ruby tools like RubyGems and Rake are suggested.
To learn more about RubyMotion, have a look at this free screencast from Pragmatic Studio
Top 5 Tips for Working With RubyMotion
1. Use CocoaPods and don’t reinvent the wheel.
CocoaPods allows you to easily import Objective-C libraries into your RubyMotion apps and use them just like any other iOS API, sort of like RubyGems. The iOS SDK has been around awhile longer than RubyMotion, and there are some very mature projects (like Nimbus and AFNetworking) that you can and should leverage whenever possible. For more info, check out the RubyMotion article on integrating with CocoaPods
2. Debug apps on your device.
Very recently, RubyMotion added a debugging tool you can use while your app is running on your device. This allows you to set breakpoints, inspect variables, and get the backtrace of some tricky crashes. It’s not a full REPL like you can use on the simulator, but it really can help track down some particularly tricky problems. The RubyMotion developer docs are a great starting point: RubyMotion
3. Write your own RubyGems!
In the book we use third-party libraries like BubbleWrap, but they don’t cover every facet of iOS development (yet!). If you find yourself using an iOS-C API and thinking, “Hmm, this isn’t very Ruby-like”, then absolutely consider writing a small wrapper and sharing it with the world. You need only to move a few files around and add a `Gemspec` file. You can convert your project to a RubyMotion-compatible RubyGem in a few minutes by following this guide: Gems
4. Use TestFlight to distribute beta versions of your app.
TestFlight is a service that allows you to send in-development copies of your app to users without hooking up their device to your computer, as well as collect crash reports and usage statistics if you desire. The RubyMotion team has come out with a small gem which allows you to upload your app to TestFlight with one simple command, and it’s a real time-saver. It only takes a minute, so check out their post at TestFlight
5. Tell the community what you’re up to!
The RubyMotion usergroup is very active and is continually collaborating on new libraries, tutorials, or just news announcements. So if you get your RubyMotion app on the App Store or publish some code on Github, definitely add a post. I hang around there too, and I’d love to hear if this book helped!
Q&A with Clay Allsopp, author of RubyMotion
Q: Why did you write RubyMotion?
There are so many developers who want to write iOS apps but are stymied at the idea of learning Objective-C, a very different language from Ruby. With RubyMotion, learning the nuances of Objective-C is no longer a requirement for developing for the iOS platform! I wanted to write a guide to help these developers become familiar with the iOS SDK and quickly get started on the right foot.
Q: How much Ruby knowledge do I need for the book?
You need some Ruby experience, as the book jumps right into the iOS SDK without delay. But don’t worry! Only familiarity with how standard object-oriented development (classes, inheritance, etc) works in Ruby is necessary. We do use some Ruby tricks here and there, like ‘instance_variable_get’, but they are explained and easy to pick up.
Q: What is your favorite RubyMotion feature?
The workflow is much more lightweight than the usual Xcode-centric development process. All of the tools are command-line based, from building your apps, to sending it over TestFlight, to running automated tests. I can work with the tools familiar to me (Rake, RubyGems, continuous integration) and end up with exactly the same result without compromising app quality.
Q: Would RubyMotion be helpful if I already know Objective-C?
Yes, because the RubyMotion community is working to push the core ideas of iOS and mobile development in new directions. The Ruby community has always had a propensity for crafting DSLs and new abstractions, and those efforts have carried over to RubyMotion. Projects like ProMotion and Formotion have no parallels in Objective-C iOS development, and they could be a real boon to your next project.
Q: Do you discuss third-party RubyMotion libraries in the book?
Yes, we use the popular BubbleWrap library several times and show how a few others (like TeaCup and Formotion) could speed up development. If you’re interested in more RubyMotion libraries, check out the list.
Q: Will I be able to build a working iOS app of my own after reading this book?
Yes! The last chapter builds a complete API-based app from scratch, which is an incredibly common task for many developers. But even before the end, you’ll be familiar with the most typical interface components and patterns and should be comfortable jumping into any new projects.
the reviews .