Download - MacRuby to The Max
![Page 2: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/2.jpg)
WHO HERE HAS AMAC?
![Page 3: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/3.jpg)
WHO HERE HASWORKED WITH
OBJECTIVE-C?
![Page 4: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/4.jpg)
DEVELOPEDOSX OR IPHONE APPS?
![Page 5: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/5.jpg)
OBJECTIVE-C
• Object-oriented extensions to C
• Strongly typed
• Like Ruby, influenced by Smalltalk
• Primary language for Cocoa
• Garbage collection (2.0)
• 32 and 64-bit support
![Page 6: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/6.jpg)
COCOA
• Set of object-oriented frameworks
• Used for writing Max OSX and iPhone OS apps
• Includes FoundationKit, and AppKit
• Typically built using tools like XCode and Interface Builder
![Page 7: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/7.jpg)
CORE FOUNDATION
• Low level libraries that ship with Mac OSX
• Used for passing primitive types to OSX C routines
• Most routines follow ‘CF’ naming convention
• Open-Sourced by Apple as CF-Lite
![Page 8: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/8.jpg)
WHY RUBY INSTEAD OF OBJECTIVE-C?
![Page 9: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/9.jpg)
RUBY VS OBJECTIVE-C
object.method(param)
[object method:param];
=
![Page 10: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/10.jpg)
RUBY VS OBJECTIVE-C
person.set_name(“john”, “doe”)
[person setNameWithFirst:@”john” withLast:@”doe”];
=
![Page 11: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/11.jpg)
RUBY VS OBJECTIVE-C
array = []
NSMutableArray *array = [[NSMutableArray alloc] init];
=
![Page 12: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/12.jpg)
RUBY VS OBJECTIVE-C
“ string”.strip
[@“ string” stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]
=
![Page 13: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/13.jpg)
RUBY VS OBJECTIVE-C
dictionary = {“key1” => “value1”, “key2” => “value2”}
NSArray *keys = [NSArray arrayWithObjects:@”key1”,@”key2”];NSArray *data = [NSArray arrayWithObjects:@”value1”,@”value2”];NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
=
![Page 14: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/14.jpg)
RUBYCOCOA• Mac OSX framework
• Bridge between Objective-C and Ruby
• Can manipulate Objective-C objects using Ruby
• Write Cocoa apps in Ruby
• Runs on Ruby 1.8
• Ships with OSX Leopard
![Page 15: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/15.jpg)
RUBYCOCOA VS OBJECTIVE-C
setObject_forKey_(iphone, phone)
[setObject:iphone forKey:phone];
=
![Page 16: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/16.jpg)
SO WHY NOTRUBYCOCOA?
![Page 17: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/17.jpg)
WHY NOT RUBYCOCOA
• Performance
• Two runtimes
• Two garbage collectors
• Object conversions
• Syntax doesn’t feel like Ruby
![Page 18: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/18.jpg)
+
MACRUBY
![Page 19: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/19.jpg)
• Impl. of Ruby 1.9 that runs on the Objective-C runtime
• Open sourced by Apple
• Originally created by Laurent Sansonetti
• Replacing RubyCocoa
• Objects are peers with no translation layer
• Multi-core (Grand Central Dispatch)
• HotCocoa Support
MACRUBY
![Page 20: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/20.jpg)
MACRUBYObject
String
Number
Array
Hash
NSObject
NSMutableString
NSNumber
NSMutableArray
NSMutableDictionary
![Page 21: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/21.jpg)
MACRUBY
Objects
Classes
Methods
Objective-C
Objective-C
Objective-C
![Page 22: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/22.jpg)
MACRUBY>> s = “rubyconf”=> “rubyconf”
>> s.class=> NSMutableString
>> s.class.ancestors=> [NSMutableString,NSString,Comparable,NSObject,Kernel]
>> s.upcase=> “RUBYCONF”
>> s.uppercaseString=> “RUBYCONF”
![Page 23: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/23.jpg)
MACRUBY
>> NSString.new(“rubyconf”)=> “rubyconf”
>> NSString.stringWithString(“rubyconf”)=> “rubyconf”
>> NSString.alloc.initWithString(“rubyconf”)=> “rubyconf”
![Page 24: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/24.jpg)
MACRUBY>> a = []=> []
>> a.class=> NSMutableArray
>> a.class.ancestors=> [NSMutableArray,NSArray,Enumerable,NSObject,Kernel]
>> a << “RubyConf”=> [“RubyConf”]
![Page 25: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/25.jpg)
MACRUBY VS OBJECTIVE-C
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {}
![Page 26: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/26.jpg)
MACRUBY VS OBJECTIVE-C
def locationManager(manager didUpdateToLocation:newLocation
fromLocation:oldLocation)end
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {}
![Page 27: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/27.jpg)
MACRUBY VS OBJECTIVE-C
def locationManager(manager didUpdateToLocation:newLocation
fromLocation:oldLocation)end
>> locationManager(manager didUpdateToLocation:newLocation, fromLocation:oldLocation)
![Page 28: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/28.jpg)
MACRUBY VS OBJECTIVE-C
def locationManager(manager didUpdateToLocation:newLocation
fromLocation:oldLocation)end
>> locationManager(manager :didUpdateToLocation => newLocation, :fromLocation => oldLocation)
![Page 29: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/29.jpg)
MACRUBY VS OBJECTIVE-C
NSString *myString;@property(nonatomic,retain) IBOutlet NSString *myString;
attr_accessor :my_string
Interface Builder Outlets
=
# Interface (header file)
![Page 30: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/30.jpg)
MACRUBY VS OBJECTIVE-C
-(IBAction) myAction:(id)sender;
def my_action(sender)...
end
Interface Builder Actions
=
# Interface
-(IBAction) myAction:(id)sender { ... }# Implementation
![Page 31: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/31.jpg)
WAIT, WHAT ABOUT MACRUBY FOR IPHONE/IPAD?
![Page 32: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/32.jpg)
MACRUBY
Xcode
![Page 33: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/33.jpg)
MACRUBY
Interface Builder
![Page 34: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/34.jpg)
MACRUBY
Instruments
![Page 35: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/35.jpg)
MACRUBY
Let’s build something ...
![Page 36: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/36.jpg)
TDD IN MACRUBY
• Good supports for tests
• Any Ruby testing framework instantly becomes an Objective-C testing framework
• Test::Unit
• RSpec
• Cucumber
• etc...
![Page 37: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/37.jpg)
HOTCOCOA
• Use Ruby to build a UI without Interface Builder
• Developed by Rich Kilmer
• MacRuby 0.5 now supports HotCocoa
• Packaged as a gem in MacRuby 0.5
![Page 38: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/38.jpg)
MACRUBY VS HOTCOCOA
win = NSWindow.alloc.initWithContentRect([10,20,300,300],:styleMask => (NSTitleWindowMask | NSCloseableWindowMask | NSMiniatureizableWindowMask | NSResizeableWindowMask)
win = window :frame => [10,20,300,300]
=
![Page 39: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/39.jpg)
HELLO WORLD IN HOTCOCOA
require ‘rubygems’require ‘hotcocoa’include HotCocoaapplication do |app|win = window :size => [100,50]b = button :title => ‘Hello’b.on_action { puts ‘World!’ }win << b
end
![Page 40: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/40.jpg)
MACRUBY
Very exciting future
![Page 41: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/41.jpg)
MACRUBY
It’s Ruby for Cocoa Apps!
![Page 42: MacRuby to The Max](https://reader033.vdocument.in/reader033/viewer/2022050613/5555a834d8b42a52568b47c7/html5/thumbnails/42.jpg)
MACRUBY
http://macruby.orghttp://macruby.org/hotcocoa.html
http://bit.ly/macruby-getting-startedhttp://bit.ly/macruby-examples
http://bit.ly/tdd-macrubyhttp://github.com/masterkain/macruby
Questions?