SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Developing Cocoa
                      Applications With

                       MacRuby
                             Brendan G. Lim
                                 @brendanlim
                             brendan@intridea.com


Saturday, February 5, 2011
Outline
                             •   Objective-C & Cocoa
                             •   RubyCocoa
                             •   MacRuby
                             •   Live Coding
                             •   HotCocoa




Saturday, February 5, 2011
Objective -C
                             •   Object-oriented extensions to C
                             •   Strongly typed
                             •   Like Ruby, influenced by Smalltalk
                             •   Primarily used for Mac OS X and iOS




Saturday, February 5, 2011
Cocoa
                    •   High-level API for Mac OS X

                    •   Set of frameworks

                    •   Includes FoundationKit, AppKit, etc.

                    •   Apps typically built using tools like XCode
                        and Interface Builder




Saturday, February 5, 2011
Why make desktop apps?




Saturday, February 5, 2011
Different Paradigm




Saturday, February 5, 2011
Mac App Store


                                  1. Build MacRuby application
                                  2. Submit to App Store
                                  4. Profit




Saturday, February 5, 2011
Why Ruby instead
                              of Objective-C?



Saturday, February 5, 2011
Apple Loves Ruby

                             2002   Mac OS X 10.2           Ruby 1.6.7

                             2005   Mac OS X 10.4           Ruby 1.8.2

                             2007   Mac OS X 10.5          Ruby 1.8.6
                                                        RubyCocoa, RubyGems, Rails


                             2009   Mac OS X 10.6           Ruby 1.8.7
                                                        RubyCocoa, RubyGems, Rails


                             2011   Mac OS X 10.7          Ruby 1.9.x?
                                                    MacRuby? RubyCocoa, RubyGems, Rails




Saturday, February 5, 2011
Ruby vs Objective-C

                              object.method(param)
                                       =

                             [object method:param];




Saturday, February 5, 2011
Ruby vs Objective-C

                              array = []
                                  =
               NSMutableArray *array =
            [[NSMutableArray alloc] init];



Saturday, February 5, 2011
Ruby vs Objective-C

                             “ string”.strip
                                    =
       [@“ string” stringByTrimmingCharactersInSet:
    [NSCharacterSet whitespaceAndNewlineCharacterSet]]




Saturday, February 5, 2011
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];




Saturday, February 5, 2011
+




Saturday, February 5, 2011
RubyCocoa
                •   Bridge between Objective-C and Ruby

                •   Manipulate Objective-C objects using Ruby

                •   Write Cocoa apps in Ruby

                •   Runs on Ruby 1.8

                •   Ships with OSX Leopard



Saturday, February 5, 2011
RubyCocoa vs Objective-C
   OSX::NSNotificationCenter.defaultCenter.addObserver_selector_name_object(
     self,
      :window_moved,
      "NSWindowDidMoveNotification",
      nil
   )

                                      =
   [[NSNotificationCenter defaultCenter] addObserver:self,
     selector:@selector(windowMoved:)
     name:”NSWindowDidMoveNotification”
     object:nil];




Saturday, February 5, 2011
So, Why Not
                             RubyCocoa?
                             (besides it looking gross)




Saturday, February 5, 2011
Why Not RubyCocoa?
                             •   It’s a bridge!

                                 •   Two runtimes, GCs, etc.

                                 •   Object conversions

                             •   Syntax doesn’t feel like idiomatic Ruby

                             •   It’s getting replaced



Saturday, February 5, 2011
+




Saturday, February 5, 2011
MacRuby

              •   Implementation of Ruby 1.9 that runs on top
                  the Objective-C runtime

              •   Open sourced and supported by Apple

              •   Replacing RubyCocoa

              •   Objects are peers with no translation layer



Saturday, February 5, 2011
MacRuby
                             Object     NSObject
                             String     NSMutableString
                             Number     NSNumber
                             Array      NSMutableArray
                             Hash       NSMutableDictionary




Saturday, February 5, 2011
MacRuby

                             Objects   Objective-C
                             Classes   Objective-C
                             Methods   Objective-C




Saturday, February 5, 2011
MacRuby
     >> s = “magicruby”
     => “magicruby”

     >> s.class
     => String

     >> s.class.ancestors
     => [String,NSMutableString,NSString,Comparable,NSObject,Kernel]

     >> s.upcase
     => “MAGICRUBY”

     >> s.uppercaseString
     => “MAGICRUBY”




Saturday, February 5, 2011
MacRuby

     >> NSString.new(“magicruby”)
     => “magicruby”

     >> NSString.stringWithString(“magicruby”)
     => “magicruby”

     >> NSString.alloc.initWithString(“magicruby”)
     => “magicruby”




Saturday, February 5, 2011
MacRuby
     >> a = []
     => []

     >> a.class
     => Array

     >> a.class.ancestors
     => [Array,NSMutableArray,NSArray,Enumerable,NSObject,Kernel]

     >> a << “MagicRuby”
     => [“MagicRuby”]




Saturday, February 5, 2011
MacRuby vs Objective-C
      -(id)       tableView:(NSTableView *)tableView
       objectValueForColumn:(NSTableColumn *)column
                        row:(int)rowIndex { .. }




Saturday, February 5, 2011
MacRuby vs Objective-C
      -(id)       tableView:(NSTableView *)tableView
       objectValueForColumn:(NSTableColumn *)column
                        row:(int)rowIndex { .. }




         def tableView(tableView
               objectValueForColumn:column
               row:rowIndex)
         end



Saturday, February 5, 2011
MacRuby vs Objective-C
                             Interface Builder Outlets & Actions




                                                                   !




Saturday, February 5, 2011
MacRuby vs Objective-C
                                Interface Builder Outlets

         # Interface
         NSString *myString;
         @property(nonatomic,retain) IBOutlet NSString *myString;


                                           =

                             attr_accessor :myString




Saturday, February 5, 2011
MacRuby vs Objective-C
                              Interface Builder Actions

             # Implementation
             -(IBAction) myAction:(id)sender { ... }


                                         =

                             def myAction(sender)
                              ...
                             end


Saturday, February 5, 2011
MacRuby - Gem Support

                             •   sudo macgem install awesome_gem

                             •   Not all gems supported right now




Saturday, February 5, 2011
MacRuby - Objective-C
                      Frameworks & Libraries

              •   Libraries must have garbage collection support

              •   Libraries must be turned into bundles

              •   Frameworks can easily be included




Saturday, February 5, 2011
Testing MacRuby

                 •   Any Ruby testing framework instantly becomes
                     an Objective-C testing framework

                     •   Test::Unit

                     •   RSpec

                     •   etc...



Saturday, February 5, 2011
What tools will we
                                be using?



Saturday, February 5, 2011
Xcode



Saturday, February 5, 2011
Interface Builder



Saturday, February 5, 2011
Instruments

Saturday, February 5, 2011
Let’s build a MacRuby app




Saturday, February 5, 2011
HotCocoa

               •    Created by Rich Kilmer

               •    Ruby layer that sits on top of Cocoa, etc.

               •    Use Ruby to easily create user interfaces

               •    Used to be included with MacRuby

               •    Now available as a gem



Saturday, February 5, 2011
HotCocoa
                win = NSWindow.alloc.initWithContentRect([10,20,300,300],
                   styleMask: (NSTitleWindowMask           |
                               NSCloseableWindowMask       |
                               NSMiniatureizableWindowMask |
                               NSResizeableWindowMask)



                                           =

                win = window :frame => [10,20,300,300]




Saturday, February 5, 2011
HotCocoa

                             sudo macgem install hotcocoa

                               hotcocoa NAME_OF_APP




Saturday, February 5, 2011
Hello World in HotCocoa
    require ‘hotcocoa’

    class Application
      include HotCocoa

      def start
        application :name => "Hello" do |app|
          app.delegate = self
          window :frame => [500,500,200,100], :title => "Hello" do |win|
            win << label(:text => "Hello World",:layout => {:start => false})
            win.will_close { exit }
          end
        end
      end
    end

    Application.new.start



Saturday, February 5, 2011
Questions?

                                         MacRuby in Action
                                         http://manning.com/lim




                                       http://macruby.org
                             http://bit.ly/macruby-getting-started
                                http://bit.ly/macruby-examples
                                   http://bit.ly/tdd-macruby
Saturday, February 5, 2011

Contenu connexe

En vedette

Mahatma Gandhi
Mahatma GandhiMahatma Gandhi
Mahatma Gandhi
Heena Modi
 
Vegetarian vision
Vegetarian visionVegetarian vision
Vegetarian vision
Heena Modi
 
Transcript - Facebook Marketing Success Summit Ads Presentation 2011
Transcript - Facebook Marketing Success Summit Ads Presentation 2011Transcript - Facebook Marketing Success Summit Ads Presentation 2011
Transcript - Facebook Marketing Success Summit Ads Presentation 2011
Chris Treadaway
 
Schloss mirabell
Schloss mirabellSchloss mirabell
Schloss mirabell
Heena Modi
 
ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...
ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...
ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...
bryonmain
 
Milieu Problematiek
Milieu ProblematiekMilieu Problematiek
Milieu Problematiek
T_COOLS
 
Facebook Marketing Success Summit Presentation 2011 - Success with Facebook Ads
Facebook Marketing Success Summit Presentation 2011 - Success with Facebook AdsFacebook Marketing Success Summit Presentation 2011 - Success with Facebook Ads
Facebook Marketing Success Summit Presentation 2011 - Success with Facebook Ads
Chris Treadaway
 
EuP Directive About Non Directional Domestic Lighting
EuP Directive About Non Directional Domestic LightingEuP Directive About Non Directional Domestic Lighting
EuP Directive About Non Directional Domestic Lighting
Heena Modi
 
July 10th 2014 - to use with members from multiple Unions
July 10th 2014 - to use with members from multiple UnionsJuly 10th 2014 - to use with members from multiple Unions
July 10th 2014 - to use with members from multiple Unions
Heena Modi
 
Woman De John Lennon
Woman De John LennonWoman De John Lennon
Woman De John Lennon
MISANTLA
 

En vedette (20)

Kansas sights
Kansas sightsKansas sights
Kansas sights
 
New  Forodhani ( Jubilee Garden ) Being Rebuilt
New  Forodhani ( Jubilee Garden ) Being RebuiltNew  Forodhani ( Jubilee Garden ) Being Rebuilt
New  Forodhani ( Jubilee Garden ) Being Rebuilt
 
Bio - Jean Fares Couture
Bio - Jean Fares CoutureBio - Jean Fares Couture
Bio - Jean Fares Couture
 
Tips
TipsTips
Tips
 
Father
FatherFather
Father
 
Mahatma Gandhi
Mahatma GandhiMahatma Gandhi
Mahatma Gandhi
 
Vegetarian vision
Vegetarian visionVegetarian vision
Vegetarian vision
 
Adjective Jingle
Adjective JingleAdjective Jingle
Adjective Jingle
 
Transcript - Facebook Marketing Success Summit Ads Presentation 2011
Transcript - Facebook Marketing Success Summit Ads Presentation 2011Transcript - Facebook Marketing Success Summit Ads Presentation 2011
Transcript - Facebook Marketing Success Summit Ads Presentation 2011
 
Schloss mirabell
Schloss mirabellSchloss mirabell
Schloss mirabell
 
The broiler hen
The broiler hen The broiler hen
The broiler hen
 
Porting the QALL-ME framework to Romanian
Porting the QALL-ME framework to RomanianPorting the QALL-ME framework to Romanian
Porting the QALL-ME framework to Romanian
 
ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...
ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...
ExL Pharma Clinical Trials Phase I and Phase IIa Conference Brochure: Phase 1...
 
Milieu Problematiek
Milieu ProblematiekMilieu Problematiek
Milieu Problematiek
 
Facebook Marketing Success Summit Presentation 2011 - Success with Facebook Ads
Facebook Marketing Success Summit Presentation 2011 - Success with Facebook AdsFacebook Marketing Success Summit Presentation 2011 - Success with Facebook Ads
Facebook Marketing Success Summit Presentation 2011 - Success with Facebook Ads
 
Mother
MotherMother
Mother
 
EuP Directive About Non Directional Domestic Lighting
EuP Directive About Non Directional Domestic LightingEuP Directive About Non Directional Domestic Lighting
EuP Directive About Non Directional Domestic Lighting
 
10 words
10 words10 words
10 words
 
July 10th 2014 - to use with members from multiple Unions
July 10th 2014 - to use with members from multiple UnionsJuly 10th 2014 - to use with members from multiple Unions
July 10th 2014 - to use with members from multiple Unions
 
Woman De John Lennon
Woman De John LennonWoman De John Lennon
Woman De John Lennon
 

Similaire à Developing Cocoa Applications with macRuby

Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
Caridy Patino
 
MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoa
Thilo Utke
 

Similaire à Developing Cocoa Applications with macRuby (20)

RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011RVM and Ruby Interpreters @ RSC Roma 03/2011
RVM and Ruby Interpreters @ RSC Roma 03/2011
 
Charla ruby nscodermad
Charla ruby nscodermadCharla ruby nscodermad
Charla ruby nscodermad
 
MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby Developers
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
 
RubyMotion
RubyMotionRubyMotion
RubyMotion
 
Intro for RoR
Intro for RoRIntro for RoR
Intro for RoR
 
I phone udvikling best brains
I phone udvikling best brainsI phone udvikling best brains
I phone udvikling best brains
 
MacRuby on Rails
MacRuby on RailsMacRuby on Rails
MacRuby on Rails
 
Sqlpo Presentation
Sqlpo PresentationSqlpo Presentation
Sqlpo Presentation
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & How
 
Caridy patino - node-js
Caridy patino - node-jsCaridy patino - node-js
Caridy patino - node-js
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)
 
MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoa
 
MacRuby for Fun and Profit
MacRuby for Fun and ProfitMacRuby for Fun and Profit
MacRuby for Fun and Profit
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
 
Introduzione a macruby
Introduzione a macrubyIntroduzione a macruby
Introduzione a macruby
 

Plus de Brendan Lim

The Lure Of Ubiquitous Mobile
The Lure Of Ubiquitous MobileThe Lure Of Ubiquitous Mobile
The Lure Of Ubiquitous Mobile
Brendan Lim
 

Plus de Brendan Lim (7)

Introduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKIntroduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDK
 
Building Native Apps With Titanium Mobile
Building Native Apps With Titanium MobileBuilding Native Apps With Titanium Mobile
Building Native Apps With Titanium Mobile
 
Im Mobile Who's Coming With Me
Im Mobile Who's Coming With MeIm Mobile Who's Coming With Me
Im Mobile Who's Coming With Me
 
MacRuby to The Max
MacRuby to The MaxMacRuby to The Max
MacRuby to The Max
 
The Lure Of Ubiquitous Mobile
The Lure Of Ubiquitous MobileThe Lure Of Ubiquitous Mobile
The Lure Of Ubiquitous Mobile
 
Mobilizing Your Rails Application - Rails Underground, London, UK
Mobilizing Your Rails Application - Rails Underground, London, UKMobilizing Your Rails Application - Rails Underground, London, UK
Mobilizing Your Rails Application - Rails Underground, London, UK
 
Mobilizing Your Rails Application - LA Ruby Conference 2009
Mobilizing Your Rails Application - LA Ruby Conference 2009Mobilizing Your Rails Application - LA Ruby Conference 2009
Mobilizing Your Rails Application - LA Ruby Conference 2009
 

Dernier

Dernier (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Developing Cocoa Applications with macRuby

  • 1. Developing Cocoa Applications With MacRuby Brendan G. Lim @brendanlim brendan@intridea.com Saturday, February 5, 2011
  • 2. Outline • Objective-C & Cocoa • RubyCocoa • MacRuby • Live Coding • HotCocoa Saturday, February 5, 2011
  • 3. Objective -C • Object-oriented extensions to C • Strongly typed • Like Ruby, influenced by Smalltalk • Primarily used for Mac OS X and iOS Saturday, February 5, 2011
  • 4. Cocoa • High-level API for Mac OS X • Set of frameworks • Includes FoundationKit, AppKit, etc. • Apps typically built using tools like XCode and Interface Builder Saturday, February 5, 2011
  • 5. Why make desktop apps? Saturday, February 5, 2011
  • 7. Mac App Store 1. Build MacRuby application 2. Submit to App Store 4. Profit Saturday, February 5, 2011
  • 8. Why Ruby instead of Objective-C? Saturday, February 5, 2011
  • 9. Apple Loves Ruby 2002 Mac OS X 10.2 Ruby 1.6.7 2005 Mac OS X 10.4 Ruby 1.8.2 2007 Mac OS X 10.5 Ruby 1.8.6 RubyCocoa, RubyGems, Rails 2009 Mac OS X 10.6 Ruby 1.8.7 RubyCocoa, RubyGems, Rails 2011 Mac OS X 10.7 Ruby 1.9.x? MacRuby? RubyCocoa, RubyGems, Rails Saturday, February 5, 2011
  • 10. Ruby vs Objective-C object.method(param) = [object method:param]; Saturday, February 5, 2011
  • 11. Ruby vs Objective-C array = [] = NSMutableArray *array = [[NSMutableArray alloc] init]; Saturday, February 5, 2011
  • 12. Ruby vs Objective-C “ string”.strip = [@“ string” stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] Saturday, February 5, 2011
  • 13. 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]; Saturday, February 5, 2011
  • 15. RubyCocoa • Bridge between Objective-C and Ruby • Manipulate Objective-C objects using Ruby • Write Cocoa apps in Ruby • Runs on Ruby 1.8 • Ships with OSX Leopard Saturday, February 5, 2011
  • 16. RubyCocoa vs Objective-C OSX::NSNotificationCenter.defaultCenter.addObserver_selector_name_object( self, :window_moved, "NSWindowDidMoveNotification", nil ) = [[NSNotificationCenter defaultCenter] addObserver:self, selector:@selector(windowMoved:) name:”NSWindowDidMoveNotification” object:nil]; Saturday, February 5, 2011
  • 17. So, Why Not RubyCocoa? (besides it looking gross) Saturday, February 5, 2011
  • 18. Why Not RubyCocoa? • It’s a bridge! • Two runtimes, GCs, etc. • Object conversions • Syntax doesn’t feel like idiomatic Ruby • It’s getting replaced Saturday, February 5, 2011
  • 20. MacRuby • Implementation of Ruby 1.9 that runs on top the Objective-C runtime • Open sourced and supported by Apple • Replacing RubyCocoa • Objects are peers with no translation layer Saturday, February 5, 2011
  • 21. MacRuby Object NSObject String NSMutableString Number NSNumber Array NSMutableArray Hash NSMutableDictionary Saturday, February 5, 2011
  • 22. MacRuby Objects Objective-C Classes Objective-C Methods Objective-C Saturday, February 5, 2011
  • 23. MacRuby >> s = “magicruby” => “magicruby” >> s.class => String >> s.class.ancestors => [String,NSMutableString,NSString,Comparable,NSObject,Kernel] >> s.upcase => “MAGICRUBY” >> s.uppercaseString => “MAGICRUBY” Saturday, February 5, 2011
  • 24. MacRuby >> NSString.new(“magicruby”) => “magicruby” >> NSString.stringWithString(“magicruby”) => “magicruby” >> NSString.alloc.initWithString(“magicruby”) => “magicruby” Saturday, February 5, 2011
  • 25. MacRuby >> a = [] => [] >> a.class => Array >> a.class.ancestors => [Array,NSMutableArray,NSArray,Enumerable,NSObject,Kernel] >> a << “MagicRuby” => [“MagicRuby”] Saturday, February 5, 2011
  • 26. MacRuby vs Objective-C -(id) tableView:(NSTableView *)tableView objectValueForColumn:(NSTableColumn *)column row:(int)rowIndex { .. } Saturday, February 5, 2011
  • 27. MacRuby vs Objective-C -(id) tableView:(NSTableView *)tableView objectValueForColumn:(NSTableColumn *)column row:(int)rowIndex { .. } def tableView(tableView objectValueForColumn:column row:rowIndex) end Saturday, February 5, 2011
  • 28. MacRuby vs Objective-C Interface Builder Outlets & Actions ! Saturday, February 5, 2011
  • 29. MacRuby vs Objective-C Interface Builder Outlets # Interface NSString *myString; @property(nonatomic,retain) IBOutlet NSString *myString; = attr_accessor :myString Saturday, February 5, 2011
  • 30. MacRuby vs Objective-C Interface Builder Actions # Implementation -(IBAction) myAction:(id)sender { ... } = def myAction(sender) ... end Saturday, February 5, 2011
  • 31. MacRuby - Gem Support • sudo macgem install awesome_gem • Not all gems supported right now Saturday, February 5, 2011
  • 32. MacRuby - Objective-C Frameworks & Libraries • Libraries must have garbage collection support • Libraries must be turned into bundles • Frameworks can easily be included Saturday, February 5, 2011
  • 33. Testing MacRuby • Any Ruby testing framework instantly becomes an Objective-C testing framework • Test::Unit • RSpec • etc... Saturday, February 5, 2011
  • 34. What tools will we be using? Saturday, February 5, 2011
  • 38. Let’s build a MacRuby app Saturday, February 5, 2011
  • 39. HotCocoa • Created by Rich Kilmer • Ruby layer that sits on top of Cocoa, etc. • Use Ruby to easily create user interfaces • Used to be included with MacRuby • Now available as a gem Saturday, February 5, 2011
  • 40. HotCocoa win = NSWindow.alloc.initWithContentRect([10,20,300,300], styleMask: (NSTitleWindowMask | NSCloseableWindowMask | NSMiniatureizableWindowMask | NSResizeableWindowMask) = win = window :frame => [10,20,300,300] Saturday, February 5, 2011
  • 41. HotCocoa sudo macgem install hotcocoa hotcocoa NAME_OF_APP Saturday, February 5, 2011
  • 42. Hello World in HotCocoa require ‘hotcocoa’ class Application include HotCocoa def start application :name => "Hello" do |app| app.delegate = self window :frame => [500,500,200,100], :title => "Hello" do |win| win << label(:text => "Hello World",:layout => {:start => false}) win.will_close { exit } end end end end Application.new.start Saturday, February 5, 2011
  • 43. Questions? MacRuby in Action http://manning.com/lim http://macruby.org http://bit.ly/macruby-getting-started http://bit.ly/macruby-examples http://bit.ly/tdd-macruby Saturday, February 5, 2011