macruby & rubymotion - madridrb may 2012
TRANSCRIPT
![Page 1: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/1.jpg)
MacRuby & RubyMotionProgramming OS X and iOS apps with Ruby
![Page 2: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/2.jpg)
HiI’m @MarkVillacampa
![Page 3: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/3.jpg)
BlameHim
![Page 4: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/4.jpg)
MacRuby
An implementation of the Ruby language that runs on top of the Objective-C runtime and garbage collection (libauto)
Based on Ruby 1.9
Uses LLVM and supports both ahead-of-time and just-in-time compilation
Ships with OS X 10.7 Lion!!
![Page 5: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/5.jpg)
MacRuby
Started by Laurent Sansonetti inside Apple
Initial 0.1 release in March 2008
Latest stable release (0.10) March 2011
Nightlies are very stable (0.12)
http://macruby.org/
https://github.com/MacRuby/MacRuby
![Page 6: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/6.jpg)
Cocoa
Apple's native object-oriented API for the Mac OS X operating system
Foundation Kit + Application Kit + Core Data frameworks
Cocoa Touch: Includes gesture recognition and different UI to use in iOS
![Page 7: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/7.jpg)
![Page 8: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/8.jpg)
How to installInstall XCode (Mac App Store, Free)
Install Command Line Tools (Preferences > Downloads)
Install MacRuby Nightly
If you are in OS X 10.6.8, install Bridge Support Preview 3
https://github.com/MacRuby/MacRuby/wiki/Setting-up-MacRuby
![Page 9: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/9.jpg)
Key concepts:MacRuby objects are Objective-C objects
>> "Hello Madridrb!".class.ancestors=> [String, NSMutableString, NSString, Comparable, NSObject, Kernel]
Can use Ruby & Cocoa methods
>> "Hello Madridrb!".upcase <- Ruby=> "HELLO MADRIDRB!">> "Hello Madridrb!".uppercaseString <- Cocoa=> "HELLO MADRIDRB!"
![Page 10: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/10.jpg)
Key concepts:
New method syntax: named parameters
Cocoa classes need to be allocated and initialized
>> NSString.alloc.initWithString(“Hello Madridrb!”)=> "Hello Madridrb!"
>> NSDictionary.alloc.initWithObjects(["foo"], forKeys: ["bar"])=> {"foo"=>"bar"}
![Page 11: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/11.jpg)
1. The syntax
![Page 12: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/12.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 13: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/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: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/14.jpg)
2. XCode
![Page 15: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/15.jpg)
![Page 16: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/16.jpg)
Interface Builder
![Page 17: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/17.jpg)
3. REPL Console( Read Eva l P r i n t Loop )
![Page 18: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/18.jpg)
![Page 19: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/19.jpg)
4. Gems
![Page 20: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/20.jpg)
Any gem that works with Ruby 1.9 should work with MacRuby
![Page 21: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/21.jpg)
5. Behaviour-Driven Development
![Page 22: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/22.jpg)
A small RSpec clone, with NSRunLoop powers.
https://github.com/alloy/MacBacon
MacBacon
![Page 23: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/23.jpg)
6. Mac App Store
![Page 24: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/24.jpg)
http://briquetteapp.com/
![Page 25: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/25.jpg)
http://shop.oreilly.com/product/0636920000723.do http://manning.com/lim/
![Page 26: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/26.jpg)
RubyMotion
Built 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 27: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/27.jpg)
RubyMotion
Commercial product. Educational licenses available at discounted price.
Laurent Sansonetti left Apple to work on it.
Released May 3rd, 2012
Fast growing community!
![Page 28: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/28.jpg)
![Page 29: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/29.jpg)
HelloMadridrb
app
app_delegate.rb
resources
spec
main_spec.rb
.gitignore
Rakefile
$ motion create HelloMadridrb
.rb files
Main delegate
Images, Sounds, .xib files
Tests
Configuration file
![Page 30: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/30.jpg)
1. Interactive Console
![Page 31: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/31.jpg)
Holding and clicking in a UI element assigns that element to the self variable in the console
![Page 32: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/32.jpg)
2. CocoaPods
![Page 33: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/33.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 'JSONKit' endend
![Page 34: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/34.jpg)
3. TestFlight
![Page 35: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/35.jpg)
TestFlight helps you distribute development builds of your app to your betatesters.
$ sudo gem install motion-testflight
Download TestFlight’s SDK and put it in the “vendor” directory inside your app.
require 'motion-testflight'
Motion::Project::App.setup do |app| # ... app.testflight.sdk = 'vendor/TestFlight' app.testflight.api_token = '<API token>' app.testflight.team_token = '<team token>'end
http://testflightapp.com/sdk/download
Edit Rakefile:
$ rake testflight notes='First release!'
Run:
![Page 36: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/36.jpg)
4. App Store
![Page 37: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/37.jpg)
http://itunes.apple.com/us/app/mustachio/id525324802
https://github.com/HipByte/Mustachio
Mustachio
![Page 38: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/38.jpg)
Demo time
![Page 39: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/39.jpg)
Questions?
![Page 40: MacRuby & RubyMotion - Madridrb May 2012](https://reader033.vdocument.in/reader033/viewer/2022042814/554a56d7b4c9054b328b4be0/html5/thumbnails/40.jpg)
No, it doesn’t run Rails.