SlideShare a Scribd company logo
1 of 91
Download to read offline
MacRuby & HotCocoa
Tasty Apps for OS X




                      Thilo Utke 2009
Overview
     About - Web developer - macruby - - Upstream - Alex - Web developer - WebApplications - doningtext
     - forex-metal - In business for a while - bootstrap - Paper-C - fast - rails - ruby - reliable - testing - rspec
     - cucumber - ruby - reliable - macs - ruby - rails - text mate - fast - plugins - gems - tools - interesting
     techs - iphone - mac - tools - Objective-C - features like ruby - smalltalk - more code - Hello World
     Example - not so fast - unlike ruby - dropped it - heard about macruby 0.3 relase - on top of Obj-C -
     get curious - less code - on Mac - with Cocoa - major API - Desktop Applications - More like ruby -
     liked it - Its from Apple! - from - RubyWrapper for NSObject 2001 - Integration with ProjectBuilder (IB
     2002) - 2006 Laurent Sansonetti - 10.5 shipped with OS X - 2008 MacRuby shall replace RubyCocoa -
     RubyCocoa is a scripting Bridge - Syntactic Sugar - Syntax Mismatch - 2 Object Graphs - Green
     Threads vs. native Threads - Ruby 1.8 and ObjectiveC - Standard Libs Broken - Slow!!! - Mismatch like
     String != NSString => more Code - Picture - Ruby first Class Citizen - MacRuby - Ruby 1.9 - Native
     Threads - Matches better with Obj Syntax - Faster - Tighter Integration with Obj-C - Share Base classes
     - Share Infrastructure - GC - MacRuby 0.5 - the best Ruby for Mac - In Development - NO GLI - Share
     IO - On top of LLVM - Doing optimizations - Calls Obj-C - class/methods/obj all Obj C - show Methods
     - No more libffi but uses a new C-dispatcher - Picture! - Show Mixing MacRuby with ObjC - Compiles
     Code JIT - soon AOT - other Platforms - iPhone? - IB integration! - Framework - main_rm - Outlet -
     Action - Delegates - Like ActiveRecord Callbacks - but fixed names - you tell who handle it - first
     responder - Delegate for Application - Show Random Number Gen with IB - Code Obj-C/MacRuby-




All the things I’d like to talk about.
Outline
 Intro

 Objective-C Encounter

 Apple - Ruby

 RubyCocoa

 MacRuby 0.5

 MacRuby <-> Obj-C

 Interface Builder Integration

 Back to Code with HotCocoa

 Impact
I’m a WebDeveloper.
UPSTREAM

My Company
Alexander Lang, also Founder and Owner of Upstream
Wrote CouchPotato. Talks about Ruby Libs for CouchDB
We did Community, Productivity, Finance and Educational Websites. Our own product is
doingText.com
Rails enabled us to build WebApps really fast.
Text




I love Ruby!
To be fast and deliver reliable applications, we build software with test first.
New libraries, gems and technics keep WebDevelopment interesting.
Boring!!!!




                                                             www.flickr.com/photos/ipom


Still I get bored easily, so I play with new technologies.
Thats why I have an iPhone.
That’s why Alex has an iPhone.
That’s why we play with couchDB.
That’s why I thought Obj-C might be interesting.
SmallTalk

             Ruby                          Obj-C


Ruby and Obj-C have a common ancestry.
Ruby                                Obj-C

                                Reflective
                                Dynamic
                                Garbage Collection
                                Object Oriented




Characteristics they have in common.
Ruby             Obj-C

           Closures

           FFI, C-Ext        C-SuperSet

           methodname(1,2)   method: 1 name:2

           Interpreter       Compiler




Things that differ.
Grabbed this book to start with Obj-C.
First Objective-C App
   @interface Foo : NSObject
   {
     IBOutlet NSTextField *textField;
   }

   - (IBAction)gerneate:(id)sender;
   - (IBAction)seed:(id)sender;
   @end

   @impelemtation Foo

   - (IBAction)generate:(id)sender
   {
     int generated = (random() % 100) +1;
     [textField setIntValue:generated];
   }

   - (IBAction)seed:(id)sender
   {
     srandom(time(NULL));
     [textField setStringValue:@quot;Generator seededquot;];
   }




My first Obj-C code with header files, types, many braces and semicolons.
o_0
Felt like back in C programming class. Thrown Obj-C away.
Yes, Ruby spoiled me.
MacRuby 0.3




Heard about MacRuby with the 0.3 release.
First Objective-C App
   class Foo
   
 attr_writer :text_field
   
   
 def seed(sender)
   
 
 @text_field.StringValue = quot;Generator doesn't need to be seeded ;)quot;
   
 end
   
   
 def generate(sender)
   
 
 @text_field.StringValue = (rand(100) + 1)
   
 end
   end




Same Obj-C Tutorial App with MacRuby.
0_0/
Header files, types, braces, and semicolons are gone. Much less code. Yeah!
It is from Apple!
Apple wants Ruby to be a
                         first class citizen
                             on OS X



Where that comes from.
2001



 Ruby extension for NSObject
and NSClassFromString function
     by Hisakuni Fujimoto
2002



  RubyCocoa Project


Ruby 1.6.7 on OS X 10.2
2005




                 Ruby 1.8.2 on OS X 10.4




For a long time nothing happened.
2006




           Laurent Sansonetti from Apple
                joined RubyCocoa



Things started to move.
2007



           Ruby 1.8.6, Rails, RubyGems
                 and RubyCocoa
                  on OSX 10.5


Big move
RubyCocoa


                                                        Frameworks


        App              Std Lib                           Obj-C

   Ruby Code              GC                GC     IO      GCC
                                   Bridge
               MRI 1.8                           Obj-C Runtime


RubyCocoa Architecture
RubyCocoa
  Use Objects from Obj-C in Ruby and vice versa
  Syntax matching
    [Class initWith:(type) p1 other:(type) p2]
                                                 Frameworks
    Class.initWith_other(p1, p2)
  Extending/Inheriting/Overwriting
  App           Std Lib                             Obj-C
  Access to C-Structs
Ruby Code         GC                 GC     IO      GCC
                          Bridge
        MRI 1.8                           Obj-C Runtime
RubyCocoa
  Messaging between Obj-C and Ruby is slow!


                                             Frameworks


  App         Std Lib                           Obj-C

Ruby Code         GC             GC     IO      GCC
                        Bridge
        MRI 1.8                       Obj-C Runtime
RubyCocoa
       Two Object Spaces
          quot;Hiquot; != @quot;Hiquot;
       Green Threads vs. Native Threads Frameworks

        App               Std Lib                                Obj-C

   Ruby Code                GC                  GC         IO    GCC
                                      Bridge
               MRI 1.8                                 Obj-C Runtime


RubyCocoa can run only on the MainThread.
Ruby needs patching to allow to work with the Obj-C runtime.
RubyCocoa
  Duplicated infrastructure


                                             Frameworks


  App         Std Lib                           Obj-C

Ruby Code         GC             GC     IO      GCC
                        Bridge
        MRI 1.8                       Obj-C Runtime
RubyCocoa
  Duplicated libraries
   Ruby’s causing hang ups
                                             Frameworks


  App         Std Lib                           Obj-C

Ruby Code         GC             GC     IO      GCC
                        Bridge
        MRI 1.8                       Obj-C Runtime
Thanks to RubyCocoa for some cool apps, like GitNub.
2008



                             MacRuby
                shall replace RubyCocoa
                            in the future


The appearance of MacRuby
2009

                    MacRuby gets popular


        Ruby 1.8.7, Rails 2.3, RubyGems
                            and RubyCocoa
                               on OSX 10.6

Community starts to grow.
Gets buzz, because it for example faster than YARV.
Appears more in screencasts/conferences.

Apple Stayes true to ruby
MacRuby 0.5

            App         Std Lib
                                             Frameworks
                 Ruby Code

                                               Obj-C
          LLVM
         JIT/AOT          GC            IO     GCC
                             Obj-C Runtime


MacRuby architecture
MacRuby 0.5
         Object => NSObject
         RubySpecific extensions
  App        Std Lib
                                  Frameworks
     Ruby Code

                                    Obj-C
  LLVM   Same Primitives
 JIT/AOT     GC             IO      GCC
                 Obj-C Runtime
./miniruby -e 'p Array.new.methods(true, true)'

   [:quot;sortUsingFunction:context:quot;, :quot;exchangeObjectAtIndex:withObjectA
   tIndex:quot;, :removeAllObjects, :quot;getObjects:range:quot;, :quot;containsObject
   :inRange:quot;, :removeObjectsInRange, :removeObjectAtIndex, :removeLas
   tObject, :quot;replaceObjectAtIndex:withObject:quot;, :quot;insertObject:atInde
   x:quot;, :addObject, :quot;countByEnumeratingWithState:objects:count:quot;, :ob
   jectAtIndex, :count, :mutableCopyWithZone, :copyWithZone, :classFor
   Coder, :finalize, :hash, :isEqual, :sortUsingDescriptors, :filterUs
   ingPredicate, :initWithContentsOfURL, :initWithContentsOfFile, :sor
   tUsingSelector, :quot;removeObjectsFromIndices:numIndices:quot;, :removeObj
   ectsAtIndexes, :quot;replaceObjectsAtIndexes:withObjects:quot;, :quot;insertObj
   ects:atIndexes:quot;, :quot;sortUsingFunction:context:range:quot;, :quot;initWithOb
   jects:count:quot;, :initWithCapacity, :removeObjectsInArray, :quot;removeOb
   jectIdenticalTo:inRange:quot;, :removeObjectIdenticalTo, :quot;removeObject
   :inRange:quot;, :removeObject, :quot;removeObject:range:identical:quot;, :setAr
   ray, :quot;setObject:atIndex:quot;, :addObjectsFromArray, :quot;replaceObjectsI




With the extra second argument set on true, you can see the Obj-C methods.
MacRuby 0.5
                             Generate Obj-C calls for Ruby code
                             Intermediate Representation (IR)
            App              Std Lib
                             Optimization             Frameworks
                 Ruby Code
                             JIT compiler to execute code
                                                        GCC
          LLVM               ~ 3 x faster than YARV
         JIT/AOT                   GC         IO        LLVM
                             AOT compiler very soon
                                   Obj-C Runtime


LLVM = Low Level Virtual Machine
MacRuby 0.5
                               Generate Obj-C calls for Ruby code
                               Intermediate Representation (IR)
             App               Std Lib
                               Optimization                          Frameworks
                  Ruby Code
                               JIT compiler to execute code
                                                                          GCC
           LLVM                ~ 3 x faster than YARV
          JIT/AOT                 GC                    IO                LLVM
                               AOT compiler very soon
                                    Obj-C Runtime


AOT Compiler might allow to build for the iPhone. The garbage collection is still an open
question.
VM_DUMP_IR=1 ./miniruby -e 'p quot;Hello RailsWayCon!quot;'

   quot;Hello RailsWayCon!quot;
   IR dump ----------------------------------------------
   ; ModuleID = 'Roxor'

   define i64 @0(i64 %self, i8* %sel) {
   MainBlock:
   
 %0 = tail call i64 (i8*, i64, i8*, i8*, i8, i32, ...)*
   @rb_vm_dispatch(i8* inttoptr (i64 4309091648 to i8*), i64 %self, i8*
   inttoptr (i64 4308940784 to i8*), i8* null, i8 0, i32 1, i64
   34360384192)
 
 ; <i64> [#uses=1]
   
 ret i64 %0
   }

   declare i64 @rb_vm_dispatch(i8*, i64, i8*, i8*, i8, i32, ...)
   ------------------------------------------------------




How the IR in LLVM looks?
MacRuby 0.5
                           One runtime
            App            One Lib
                           Std object space
                                                   Frameworks
                           Shared infrastructure
                    Ruby Code
                           Multithreaded             Obj-C
           LLVM
          JIT/AOT             GC           IO        GCC
                               Obj-C Runtime


No GIL is needed.
MacRuby 0.5




MacRuby is not fully functional yet.
Not installable around 85% RubySpecs passes.
You can play with miniruby.
MacRuby 0.4




“Stable” version
Using Frameworks
       #import <Cocoa/Cocoa.h>

   framework 'Cocoa'
    
    




Require a framework
Calling Obj-C Methods
    [dog makeNoise:@”wuff” level:6];

dog.makeNoise “wuff”, level:6

dog.makeNoise “wuff”, :level => 6
 
 
Defining Methods for Obj-C
- (id) makeNoise:(NSString)noise
level:(NSInteger)level;

def makeNoise(noise, level:level)
 
Using Structs
    NSPoint(0,1)

NSpoint.new(0,1)
 
Pointer
       NSError* error;

   //MacRuby 0.4
   error = Pointer.new_with_type('@')

   //MacRuby 0.5
   error = Pointer.new(:object)
    




Pointers are often used as a means for output parameters, mostly for error handling.
alloc & init

[[NSMutableArray alloc] init]

Array.alloc.init == Array.new

Array.alloc.initWithArray([1])==
Array.arrayWithArray([1])
Use Ruby from Objective-C
   //Possible
   id dog = [NSClassFromString(@quot;Dogquot;) new];
   [dog bark]


   //Safer
   id dog = [[MacRuby sharedRuntime]
     evaluateString:@quot;Dog.newquot;];
   [dog performRubySelector: @selector(bark:)];




Ruby Parameters are always objects, careful when passing primitives!
XCode




MacRuby is supported in XCode.
Interface Builder




Also support by Interface Builder
Read this book to learn more about Interface Builder and XCode.
Interface Builder




Wire the GUI to your code.
OUTLETS


References to GUI elements
attr_writer :stalutation

attr_accessor :user_input
ACTIONS


Methods, which are supposed to be called on UI events.
def showSalutation(sender)

 
 @stalutation.stringValue = quot;Hi RailsWayCon!quot;
 end
Delegates


Specific to Ruby Cocoa and other frameworks.
def applicationDidFinishLoading(message)
     // do somehting here
    end




                                             I am your delegate



         Answer my Emails!



Alternative explanation: ActiveRecord callbacks with fixed names defined in another object.
With InterfaceBuilder you get very much, very fast, with very little code but rather static.
Good for small Apps, prototypes, App parts.
More control, understanding, flexibility.
Hello World MacRuby
   framework 'Cocoa'
    
    
   app = NSApplication.sharedApplication
    
   window = NSWindow.alloc.initWithContentRect([0,0,200,60],
     styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask ,
     backing:NSBackingStoreBuffered,
     defer:false)
    
   window.title = 'Hello World'
    
   label = NSTextField.alloc.initWithFrame(NSZeroRect)
   window.contentView.addSubview(label)
   label.stringValue = quot;Hello RailsWayCon!quot;
   label.setEditable(false)
   label.setSelectable(false)
   label.setBezeled(false)
   label.setDrawsBackground(false)
   label.sizeToFit
   label.frameOrigin = NSMakePoint((window.contentView.frameSize.width / 2) -
   (label.frameSize.width / 2)),
     (window.contentView.frameSize.height / 3))
   window.display
   window.orderFrontRegardless
    
   app.run




No InterfaceBuilder -> lots of code
by: http://www.flickr.com/photos/myphotourl
HotCocoa. Not only a tasty drink but a smart Lib shipped with MacRuby.
HotCocoa

Ruby Wrapper for major frameworks
  AppKit
  WebKit
  QtKit
  CoreGraphics
  CoreImage
HotCocoa

        Constructors with smart defaults
        Constants mapped to Symbols
        Custom methods
        Easy delegation




Constructors- Building the instances of the mapped classes using the correct class-specific
APIs
Smart Defaults - Default constructor parameters to minimize the needed parameters
Constant Mapping - Use of Ruby symbols to minimize the text and incr. readability
Custom Methods- Ruby-friendly API for commonly used methods
Delegate Methods - Ruby-friendly methods for delegating instances
Hello World HotCocoa
  require 'hotcocoa'
  include HotCocoa
   
  application do
    window = window(title: 'Hello World', frame: [0,0,200,60])
    label = label(text:'Hello RailsWayCon!', layout: {align::center})
    window << label
  end




Same App done with MacRuby.
0_0/
Constructors with Smart Defaults
NSWindow.alloc.initWithContentRect([0,0,200,60],
   styleMask:NSTitledWindowMask |
   NSClosableWindowMask |
   NSResizableWindowMask , 
   backing:NSBackingStoreBuffered,
   defer:false)




window(title: 'Hello World', frame: [0,0,200,60])
 
Constant Mappings
button.setBezelStyle(NSRoundedBezelStyle)

button.bezel = :rounded
 
Custom Methods
window.contentView.addSubview(label)


window << label
 
Delegate
button.target = self
button.action = 'sayHello'
def sayHello
 p 'Hello!'
end



botton.on_action {p 'Hello!'}
 
HotCoco Documentation

Soon


see /hotcocoa/mappings


HotConsole at gitHub to play arround
Lot of work to do to understand all available OS X frameworks.
So What?



The implications of MacRuby
Movement




           ?
Better Tool Support


 != Apple | XCode | InterfaceBuilder
 HotCocoa, Rucola (App. Gen.)
 HotConsole
Mature Testing Libraries

 TestUnit (working)
 Mocha (working)
 Rspec
 Shoulda
 Cucumber (GUI manipulation?)
More applications for MAC!
Thanks

Start: macruby.org


Help: MacRuby-devel on MacOSForge
Twitter: @MacRuby


Thilo Utke 2009 for RailsWayCon
Upstream-Agile GmbH (upstream-berlin.com)

More Related Content

What's hot

Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIelliando dias
 
Groovy Up Your Code
Groovy Up Your CodeGroovy Up Your Code
Groovy Up Your CodePaulo Traça
 
Rationalを最適化してみた
Rationalを最適化してみたRationalを最適化してみた
Rationalを最適化してみたTadashi Saito
 
Workshop de Ruby on Rails
Workshop de Ruby on RailsWorkshop de Ruby on Rails
Workshop de Ruby on RailsFabio Akita
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation platico_dev
 
Workshop de Ruby e Rails na USP Leste 2012
Workshop de Ruby e Rails na USP Leste 2012Workshop de Ruby e Rails na USP Leste 2012
Workshop de Ruby e Rails na USP Leste 2012Fabio Akita
 
FOSDEM2016 - Ruby and OMR
FOSDEM2016 - Ruby and OMRFOSDEM2016 - Ruby and OMR
FOSDEM2016 - Ruby and OMRCharlie Gracie
 
High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012Charles Nutter
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeAlexander Shopov
 

What's hot (16)

MacRuby, an introduction
MacRuby, an introductionMacRuby, an introduction
MacRuby, an introduction
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
 
Groovy Up Your Code
Groovy Up Your CodeGroovy Up Your Code
Groovy Up Your Code
 
Rationalを最適化してみた
Rationalを最適化してみたRationalを最適化してみた
Rationalを最適化してみた
 
Workshop de Ruby on Rails
Workshop de Ruby on RailsWorkshop de Ruby on Rails
Workshop de Ruby on Rails
 
From 'Legacy' to 'Edge'
From 'Legacy' to 'Edge'From 'Legacy' to 'Edge'
From 'Legacy' to 'Edge'
 
MacRuby on Rails
MacRuby on RailsMacRuby on Rails
MacRuby on Rails
 
Ruby Presentation - Beamer
Ruby Presentation - BeamerRuby Presentation - Beamer
Ruby Presentation - Beamer
 
Modular Pick and Place Simulator using ROS Framework
Modular Pick and Place Simulator using ROS FrameworkModular Pick and Place Simulator using ROS Framework
Modular Pick and Place Simulator using ROS Framework
 
Project Zero Php Quebec
Project Zero Php QuebecProject Zero Php Quebec
Project Zero Php Quebec
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Ruby's GC 20
Ruby's GC 20Ruby's GC 20
Ruby's GC 20
 
Workshop de Ruby e Rails na USP Leste 2012
Workshop de Ruby e Rails na USP Leste 2012Workshop de Ruby e Rails na USP Leste 2012
Workshop de Ruby e Rails na USP Leste 2012
 
FOSDEM2016 - Ruby and OMR
FOSDEM2016 - Ruby and OMRFOSDEM2016 - Ruby and OMR
FOSDEM2016 - Ruby and OMR
 
High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java Bytecode
 

Similar to MacRuby & HotCocoa

MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby DevelopersRenzo Borgatti
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deploymentThilo Utke
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets CocoaRobbert
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS developmenttoamitkumar
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion IntroductionLori Olson
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyelliando dias
 
Macruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich KilmerMacruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich KilmerMatt Aimonetti
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?Joshua Ballanco
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Eugene Yokota
 
Modified "Why MacRuby Matters"
Modified "Why MacRuby Matters"Modified "Why MacRuby Matters"
Modified "Why MacRuby Matters"Sean McCune
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the RubyistWill Green
 
RubyならMacでしょう
RubyならMacでしょうRubyならMacでしょう
RubyならMacでしょうvincentisambart
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Thomas Lundström
 
MacRuby & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012MacRuby & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012Mark Villacampa
 
Introduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceIntroduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceOleksii Sukhovii
 

Similar to MacRuby & HotCocoa (20)

MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby Developers
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets Cocoa
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS development
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion Introduction
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
 
Macruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich KilmerMacruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich Kilmer
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 
Web application intro
Web application introWeb application intro
Web application intro
 
Modified "Why MacRuby Matters"
Modified "Why MacRuby Matters"Modified "Why MacRuby Matters"
Modified "Why MacRuby Matters"
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the Rubyist
 
RubyならMacでしょう
RubyならMacでしょうRubyならMacでしょう
RubyならMacでしょう
 
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 & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012MacRuby & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012
 
Introduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceIntroduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function Interface
 

Recently uploaded

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

MacRuby & HotCocoa

  • 1. MacRuby & HotCocoa Tasty Apps for OS X Thilo Utke 2009
  • 2. Overview About - Web developer - macruby - - Upstream - Alex - Web developer - WebApplications - doningtext - forex-metal - In business for a while - bootstrap - Paper-C - fast - rails - ruby - reliable - testing - rspec - cucumber - ruby - reliable - macs - ruby - rails - text mate - fast - plugins - gems - tools - interesting techs - iphone - mac - tools - Objective-C - features like ruby - smalltalk - more code - Hello World Example - not so fast - unlike ruby - dropped it - heard about macruby 0.3 relase - on top of Obj-C - get curious - less code - on Mac - with Cocoa - major API - Desktop Applications - More like ruby - liked it - Its from Apple! - from - RubyWrapper for NSObject 2001 - Integration with ProjectBuilder (IB 2002) - 2006 Laurent Sansonetti - 10.5 shipped with OS X - 2008 MacRuby shall replace RubyCocoa - RubyCocoa is a scripting Bridge - Syntactic Sugar - Syntax Mismatch - 2 Object Graphs - Green Threads vs. native Threads - Ruby 1.8 and ObjectiveC - Standard Libs Broken - Slow!!! - Mismatch like String != NSString => more Code - Picture - Ruby first Class Citizen - MacRuby - Ruby 1.9 - Native Threads - Matches better with Obj Syntax - Faster - Tighter Integration with Obj-C - Share Base classes - Share Infrastructure - GC - MacRuby 0.5 - the best Ruby for Mac - In Development - NO GLI - Share IO - On top of LLVM - Doing optimizations - Calls Obj-C - class/methods/obj all Obj C - show Methods - No more libffi but uses a new C-dispatcher - Picture! - Show Mixing MacRuby with ObjC - Compiles Code JIT - soon AOT - other Platforms - iPhone? - IB integration! - Framework - main_rm - Outlet - Action - Delegates - Like ActiveRecord Callbacks - but fixed names - you tell who handle it - first responder - Delegate for Application - Show Random Number Gen with IB - Code Obj-C/MacRuby- All the things I’d like to talk about.
  • 3. Outline Intro Objective-C Encounter Apple - Ruby RubyCocoa MacRuby 0.5 MacRuby <-> Obj-C Interface Builder Integration Back to Code with HotCocoa Impact
  • 6. Alexander Lang, also Founder and Owner of Upstream
  • 7. Wrote CouchPotato. Talks about Ruby Libs for CouchDB
  • 8. We did Community, Productivity, Finance and Educational Websites. Our own product is doingText.com
  • 9. Rails enabled us to build WebApps really fast.
  • 11. To be fast and deliver reliable applications, we build software with test first.
  • 12. New libraries, gems and technics keep WebDevelopment interesting.
  • 13. Boring!!!! www.flickr.com/photos/ipom Still I get bored easily, so I play with new technologies.
  • 14. Thats why I have an iPhone.
  • 15. That’s why Alex has an iPhone.
  • 16. That’s why we play with couchDB.
  • 17. That’s why I thought Obj-C might be interesting.
  • 18. SmallTalk Ruby Obj-C Ruby and Obj-C have a common ancestry.
  • 19. Ruby Obj-C Reflective Dynamic Garbage Collection Object Oriented Characteristics they have in common.
  • 20. Ruby Obj-C Closures FFI, C-Ext C-SuperSet methodname(1,2) method: 1 name:2 Interpreter Compiler Things that differ.
  • 21. Grabbed this book to start with Obj-C.
  • 22. First Objective-C App @interface Foo : NSObject { IBOutlet NSTextField *textField; } - (IBAction)gerneate:(id)sender; - (IBAction)seed:(id)sender; @end @impelemtation Foo - (IBAction)generate:(id)sender { int generated = (random() % 100) +1; [textField setIntValue:generated]; } - (IBAction)seed:(id)sender { srandom(time(NULL)); [textField setStringValue:@quot;Generator seededquot;]; } My first Obj-C code with header files, types, many braces and semicolons.
  • 23. o_0 Felt like back in C programming class. Thrown Obj-C away. Yes, Ruby spoiled me.
  • 24. MacRuby 0.3 Heard about MacRuby with the 0.3 release.
  • 25. First Objective-C App class Foo attr_writer :text_field def seed(sender) @text_field.StringValue = quot;Generator doesn't need to be seeded ;)quot; end def generate(sender) @text_field.StringValue = (rand(100) + 1) end end Same Obj-C Tutorial App with MacRuby.
  • 26. 0_0/ Header files, types, braces, and semicolons are gone. Much less code. Yeah!
  • 27. It is from Apple!
  • 28. Apple wants Ruby to be a first class citizen on OS X Where that comes from.
  • 29. 2001 Ruby extension for NSObject and NSClassFromString function by Hisakuni Fujimoto
  • 30. 2002 RubyCocoa Project Ruby 1.6.7 on OS X 10.2
  • 31. 2005 Ruby 1.8.2 on OS X 10.4 For a long time nothing happened.
  • 32. 2006 Laurent Sansonetti from Apple joined RubyCocoa Things started to move.
  • 33. 2007 Ruby 1.8.6, Rails, RubyGems and RubyCocoa on OSX 10.5 Big move
  • 34. RubyCocoa Frameworks App Std Lib Obj-C Ruby Code GC GC IO GCC Bridge MRI 1.8 Obj-C Runtime RubyCocoa Architecture
  • 35. RubyCocoa Use Objects from Obj-C in Ruby and vice versa Syntax matching [Class initWith:(type) p1 other:(type) p2] Frameworks Class.initWith_other(p1, p2) Extending/Inheriting/Overwriting App Std Lib Obj-C Access to C-Structs Ruby Code GC GC IO GCC Bridge MRI 1.8 Obj-C Runtime
  • 36. RubyCocoa Messaging between Obj-C and Ruby is slow! Frameworks App Std Lib Obj-C Ruby Code GC GC IO GCC Bridge MRI 1.8 Obj-C Runtime
  • 37. RubyCocoa Two Object Spaces quot;Hiquot; != @quot;Hiquot; Green Threads vs. Native Threads Frameworks App Std Lib Obj-C Ruby Code GC GC IO GCC Bridge MRI 1.8 Obj-C Runtime RubyCocoa can run only on the MainThread. Ruby needs patching to allow to work with the Obj-C runtime.
  • 38. RubyCocoa Duplicated infrastructure Frameworks App Std Lib Obj-C Ruby Code GC GC IO GCC Bridge MRI 1.8 Obj-C Runtime
  • 39. RubyCocoa Duplicated libraries Ruby’s causing hang ups Frameworks App Std Lib Obj-C Ruby Code GC GC IO GCC Bridge MRI 1.8 Obj-C Runtime
  • 40. Thanks to RubyCocoa for some cool apps, like GitNub.
  • 41. 2008 MacRuby shall replace RubyCocoa in the future The appearance of MacRuby
  • 42. 2009 MacRuby gets popular Ruby 1.8.7, Rails 2.3, RubyGems and RubyCocoa on OSX 10.6 Community starts to grow. Gets buzz, because it for example faster than YARV. Appears more in screencasts/conferences. Apple Stayes true to ruby
  • 43. MacRuby 0.5 App Std Lib Frameworks Ruby Code Obj-C LLVM JIT/AOT GC IO GCC Obj-C Runtime MacRuby architecture
  • 44. MacRuby 0.5 Object => NSObject RubySpecific extensions App Std Lib Frameworks Ruby Code Obj-C LLVM Same Primitives JIT/AOT GC IO GCC Obj-C Runtime
  • 45. ./miniruby -e 'p Array.new.methods(true, true)' [:quot;sortUsingFunction:context:quot;, :quot;exchangeObjectAtIndex:withObjectA tIndex:quot;, :removeAllObjects, :quot;getObjects:range:quot;, :quot;containsObject :inRange:quot;, :removeObjectsInRange, :removeObjectAtIndex, :removeLas tObject, :quot;replaceObjectAtIndex:withObject:quot;, :quot;insertObject:atInde x:quot;, :addObject, :quot;countByEnumeratingWithState:objects:count:quot;, :ob jectAtIndex, :count, :mutableCopyWithZone, :copyWithZone, :classFor Coder, :finalize, :hash, :isEqual, :sortUsingDescriptors, :filterUs ingPredicate, :initWithContentsOfURL, :initWithContentsOfFile, :sor tUsingSelector, :quot;removeObjectsFromIndices:numIndices:quot;, :removeObj ectsAtIndexes, :quot;replaceObjectsAtIndexes:withObjects:quot;, :quot;insertObj ects:atIndexes:quot;, :quot;sortUsingFunction:context:range:quot;, :quot;initWithOb jects:count:quot;, :initWithCapacity, :removeObjectsInArray, :quot;removeOb jectIdenticalTo:inRange:quot;, :removeObjectIdenticalTo, :quot;removeObject :inRange:quot;, :removeObject, :quot;removeObject:range:identical:quot;, :setAr ray, :quot;setObject:atIndex:quot;, :addObjectsFromArray, :quot;replaceObjectsI With the extra second argument set on true, you can see the Obj-C methods.
  • 46. MacRuby 0.5 Generate Obj-C calls for Ruby code Intermediate Representation (IR) App Std Lib Optimization Frameworks Ruby Code JIT compiler to execute code GCC LLVM ~ 3 x faster than YARV JIT/AOT GC IO LLVM AOT compiler very soon Obj-C Runtime LLVM = Low Level Virtual Machine
  • 47. MacRuby 0.5 Generate Obj-C calls for Ruby code Intermediate Representation (IR) App Std Lib Optimization Frameworks Ruby Code JIT compiler to execute code GCC LLVM ~ 3 x faster than YARV JIT/AOT GC IO LLVM AOT compiler very soon Obj-C Runtime AOT Compiler might allow to build for the iPhone. The garbage collection is still an open question.
  • 48. VM_DUMP_IR=1 ./miniruby -e 'p quot;Hello RailsWayCon!quot;' quot;Hello RailsWayCon!quot; IR dump ---------------------------------------------- ; ModuleID = 'Roxor' define i64 @0(i64 %self, i8* %sel) { MainBlock: %0 = tail call i64 (i8*, i64, i8*, i8*, i8, i32, ...)* @rb_vm_dispatch(i8* inttoptr (i64 4309091648 to i8*), i64 %self, i8* inttoptr (i64 4308940784 to i8*), i8* null, i8 0, i32 1, i64 34360384192) ; <i64> [#uses=1] ret i64 %0 } declare i64 @rb_vm_dispatch(i8*, i64, i8*, i8*, i8, i32, ...) ------------------------------------------------------ How the IR in LLVM looks?
  • 49. MacRuby 0.5 One runtime App One Lib Std object space Frameworks Shared infrastructure Ruby Code Multithreaded Obj-C LLVM JIT/AOT GC IO GCC Obj-C Runtime No GIL is needed.
  • 50. MacRuby 0.5 MacRuby is not fully functional yet. Not installable around 85% RubySpecs passes. You can play with miniruby.
  • 52. Using Frameworks #import <Cocoa/Cocoa.h> framework 'Cocoa'     Require a framework
  • 53. Calling Obj-C Methods [dog makeNoise:@”wuff” level:6]; dog.makeNoise “wuff”, level:6 dog.makeNoise “wuff”, :level => 6    
  • 54. Defining Methods for Obj-C - (id) makeNoise:(NSString)noise level:(NSInteger)level; def makeNoise(noise, level:level)  
  • 55. Using Structs NSPoint(0,1) NSpoint.new(0,1)  
  • 56. Pointer NSError* error; //MacRuby 0.4 error = Pointer.new_with_type('@') //MacRuby 0.5 error = Pointer.new(:object)   Pointers are often used as a means for output parameters, mostly for error handling.
  • 57. alloc & init [[NSMutableArray alloc] init] Array.alloc.init == Array.new Array.alloc.initWithArray([1])== Array.arrayWithArray([1])
  • 58. Use Ruby from Objective-C //Possible id dog = [NSClassFromString(@quot;Dogquot;) new]; [dog bark] //Safer id dog = [[MacRuby sharedRuntime] evaluateString:@quot;Dog.newquot;]; [dog performRubySelector: @selector(bark:)]; Ruby Parameters are always objects, careful when passing primitives!
  • 59.
  • 61. Interface Builder Also support by Interface Builder
  • 62. Read this book to learn more about Interface Builder and XCode.
  • 63.
  • 64.
  • 65. Interface Builder Wire the GUI to your code.
  • 68. ACTIONS Methods, which are supposed to be called on UI events.
  • 69. def showSalutation(sender) @stalutation.stringValue = quot;Hi RailsWayCon!quot; end
  • 70. Delegates Specific to Ruby Cocoa and other frameworks.
  • 71. def applicationDidFinishLoading(message) // do somehting here end I am your delegate Answer my Emails! Alternative explanation: ActiveRecord callbacks with fixed names defined in another object.
  • 72. With InterfaceBuilder you get very much, very fast, with very little code but rather static. Good for small Apps, prototypes, App parts.
  • 74. Hello World MacRuby framework 'Cocoa'     app = NSApplication.sharedApplication   window = NSWindow.alloc.initWithContentRect([0,0,200,60],   styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask ,   backing:NSBackingStoreBuffered,   defer:false)   window.title = 'Hello World'   label = NSTextField.alloc.initWithFrame(NSZeroRect) window.contentView.addSubview(label) label.stringValue = quot;Hello RailsWayCon!quot; label.setEditable(false) label.setSelectable(false) label.setBezeled(false) label.setDrawsBackground(false) label.sizeToFit label.frameOrigin = NSMakePoint((window.contentView.frameSize.width / 2) - (label.frameSize.width / 2)),   (window.contentView.frameSize.height / 3)) window.display window.orderFrontRegardless   app.run No InterfaceBuilder -> lots of code
  • 75. by: http://www.flickr.com/photos/myphotourl HotCocoa. Not only a tasty drink but a smart Lib shipped with MacRuby.
  • 76. HotCocoa Ruby Wrapper for major frameworks AppKit WebKit QtKit CoreGraphics CoreImage
  • 77. HotCocoa Constructors with smart defaults Constants mapped to Symbols Custom methods Easy delegation Constructors- Building the instances of the mapped classes using the correct class-specific APIs Smart Defaults - Default constructor parameters to minimize the needed parameters Constant Mapping - Use of Ruby symbols to minimize the text and incr. readability Custom Methods- Ruby-friendly API for commonly used methods Delegate Methods - Ruby-friendly methods for delegating instances
  • 78. Hello World HotCocoa require 'hotcocoa' include HotCocoa   application do   window = window(title: 'Hello World', frame: [0,0,200,60])   label = label(text:'Hello RailsWayCon!', layout: {align::center})   window << label end Same App done with MacRuby.
  • 79. 0_0/
  • 80. Constructors with Smart Defaults NSWindow.alloc.initWithContentRect([0,0,200,60], styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask ,  backing:NSBackingStoreBuffered,    defer:false) window(title: 'Hello World', frame: [0,0,200,60])  
  • 83. Delegate button.target = self button.action = 'sayHello' def sayHello p 'Hello!' end botton.on_action {p 'Hello!'}  
  • 85. Lot of work to do to understand all available OS X frameworks.
  • 87. Movement ?
  • 88. Better Tool Support != Apple | XCode | InterfaceBuilder HotCocoa, Rucola (App. Gen.) HotConsole
  • 89. Mature Testing Libraries TestUnit (working) Mocha (working) Rspec Shoulda Cucumber (GUI manipulation?)
  • 91. Thanks Start: macruby.org Help: MacRuby-devel on MacOSForge Twitter: @MacRuby Thilo Utke 2009 for RailsWayCon Upstream-Agile GmbH (upstream-berlin.com)