Download - RubyMotion
![Page 1: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/1.jpg)
RubyMotionProgramming OS X and iOS apps with Ruby
![Page 2: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/2.jpg)
HiI’m @MarkVillacampa
![Page 3: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/3.jpg)
MacRuby
Started by Laurent Sansonetti inside Apple
Initial 0.1 release in March 2008
Goal: Write OS X applications in Ruby without any performance loss
![Page 4: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/4.jpg)
MacRubyAn implementation of the Ruby language that runs on top of the Objective-C runtime and garbage collection
Based on Ruby 1.9
Uses LLVM
Eventually "sunsetted" by Apple :(
![Page 5: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/5.jpg)
RubyMotionCommercial product.
Write OS X and iOS applications using Ruby
Laurent Sansonetti left Apple to work on it.
Released May 3rd, 2012
Awesome community!
![Page 6: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/6.jpg)
RubyMotionBuilt on top of MacRuby
Uses a new LLVM-based static compiler that generates optimized machine code
Memory model similar to Objective-C ARC
Based on Rake
http://www.rubymotion.com/
![Page 7: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/7.jpg)
Cocoa
Apple's native object-oriented API for OS X and iOS
Includes a lot of different libraries
Very mature (originally developed at NeXTSTEP in the 80s)
![Page 8: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/8.jpg)
![Page 9: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/9.jpg)
Key concepts:RubyMotion objects are Objective-C objects
>> "Hello Betabeers!".class.ancestors => [String, NSMutableString, NSString, Comparable, NSObject, Kernel]
![Page 10: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/10.jpg)
Key concepts:Can use Ruby & Cocoa methods
>> "Hello Madridrb!".upcase ← Ruby => "HELLO MADRIDRB!" >> "Hello Madridrb!".uppercaseString ← Cocoa => "HELLO MADRIDRB!"
![Page 11: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/11.jpg)
Key concepts:New method syntax: named parameters
>> NSDictionary.alloc.initWithObjects(["foo"], forKeys: ["bar"]) => {"foo"=>"bar"}
![Page 12: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/12.jpg)
1. The syntax
![Page 13: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/13.jpg)
Objective-C:
Ruby:
a = {"foo" => ["bar", "baz"], "oof" => 2}
NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:[NSArray arrayWithObjects:@"bar", @"baz"] forKey:@"foo"]; [dict setObject:[NSNumber numberWithInt:2] forKey:@"oof"];
![Page 14: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/14.jpg)
2. No Xcode
![Page 15: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/15.jpg)
![Page 16: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/16.jpg)
HelloMadridrb
app
app_delegate.rb
resources
spec
main_spec.rb
.gitignore
Rakefile
$ motion create MotionBetabeers
.rb filesMain delegate
Images, Sounds, .xib files
Tests
Configuration file
![Page 17: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/17.jpg)
3. Gems
![Page 18: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/18.jpg)
http://rubymotion-wrappers.com
Can't use CRuby gems ('require' is not allowed)
Many wrappers and libraries specifically created for Rubymotion and Cocoa:
https://github.com/rubymotion/motion-kit
E.g.: Motion-Kit
![Page 19: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/19.jpg)
4. TDD
![Page 20: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/20.jpg)
Bacon
http://www.rubymotion.com/developer-center/articles/testing/
Rspec syntax
Helpers to test touch UI in iOS
describe "Application" do before do @app = UIApplication.sharedApplication end ! it "has one window" do @app.windows.size.should == 1 end end
![Page 21: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/21.jpg)
6. Interactive Console (REPL)
![Page 22: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/22.jpg)
Holding and clicking in a UI element assigns that element to the self variable in the console
![Page 23: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/23.jpg)
7. CocoaPods
![Page 24: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/24.jpg)
CocoaPods is like RubyGems but for Ojective-C projects.
$ sudo gem install cocoapods $ pod setup $ sudo gem install motion-cocoapods
Choose a pod:https://github.com/CocoaPods/Specs
Edit Rakefile:
require 'motion-cocoapods' !Motion::Project::App.setup do |app| # ... app.pods do dependency 'Facebook-iOS-SDK' end end
![Page 25: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/25.jpg)
8. Production Ready
![Page 26: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/26.jpg)
http://www.rubymotion.com/apps/
Hundreds of apps in the AppStore
Used at Cabify since 2012
![Page 27: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/27.jpg)
http://www.rubymotion.com/developer-center/
![Page 28: RubyMotion](https://reader033.vdocument.in/reader033/viewer/2022052410/555a2f4ed8b42a900d8b4ec7/html5/thumbnails/28.jpg)
Thankswww.markvillacampa.com
Twitter: @MarkVillacampa