GUI Programming with

MacRuby
GUI Programming with

         MacRuby
Who?
What?
When?
Where?
Why?
How?
Who?
Erik Michaels-Ober?
sferik
on Twitter, GitHub, Gmail, IRC, &c.
Code for America
    APPLY WITHIN
I’ve committed to...
rails          oauth2       rvm

rails_admin    faraday      bunder

merb_admin     thor         travis-ci

twitter        multi_json   dummy_data

twurl          multi_xml    git-pulls

simple_oauth   octokit      mlb
HubCap
Who else?
@lrz               @benstiglitz
@merbist           @importantshock
@rich_kilmer       @naixn
@alloy             @watson1978
@vincentisambart   @Psychs
@macruby           macruby-devel
What?
What

            MacRuby


1. A complete implementation of Ruby 1.9
Ruby apps   MacRuby apps
DEMO
What

             MacRuby

1. A complete implementation of Ruby 1.9
2. Allows you to script existing Mac apps
3. Allows you to create new Mac apps
Let me tell you a
    secret...
AppleScript
Objective-C
Ruby Method Invocation
object.method parameter
Objective-C Method Invocation

[object method:parameter];
Ruby Array Initialization and Assignment


array = []
Objective-C Array Initialization and Assignment


NSMutableArray *array =
[[NSMutableArray alloc] init];
RubyCocoa
MacRuby Hello World
require 'hotcocoa'
include HotCocoa

application do |app|
  win = window :size => [100,50]
  b = button :title => 'Hello'
  b.on_action { puts 'World!' }
  win << b
end
RubyCocoa Hello World
require 'osx/cocoa'
include OSX

app = NSApplication.sharedApplication
win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(
  [0, 0, 200, 60],
  NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
  NSBackingStoreBuffered, false)

win.title = 'Hello World'
button = NSButton.alloc.initWithFrame(NSZeroRect)
win.contentView.addSubview(button)

button.bezelStyle = NSRoundedBezelStyle
button.title = 'Hello!'
button.sizeToFit

button.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0),
  (win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))
button_controller = Object.new

def button_controller.sayHello(sender)
  puts "Hello World!"
end

button.target = button_controller
button.action = 'sayHello:'
win.display
win.orderFrontRegardless

app.run
Java
Objective-J
When?
When

    MacRuby
     NOW!
   Version 0.10
Version 1.0 coming soon
When

          MacRuby
MacRuby will be included
with Mac OS X 10.7 Lion*
*currently as a private framework :(
Why?
Why

            MacRuby
• You already know Ruby
• Use existing Ruby gems
• Ruby 1.9.2
• No GIL
• Multi-threaded generational GC
• Fast!
Performance Benchmarks
 8
                                              Ruby 1.9         MacRuby
 7

 6

 5

 4

 3

 2

 1


app_answer   app_tarai   so_object   vm1_ivar_set   vm2_proc    vm2_zsuper
Average Selling Price
$12.00

$10.00

 $8.00

 $6.00
                            $11.21

 $4.00

 $2.00              $4.19

            $1.57

           iPhone   iPad    Mac
How?
How

   MacRuby

macruby.com
How

       MacRuby
rvm get head
rvm install macruby
How

        MacRuby
brew install llvm
port install llvm
How

         MacRuby
Free with ADC account at
developer.apple.com/tools/xcode
or $4.99 on the Mac App Store
sferik
on Twitter, GitHub, Gmail, IRC, &c.

GUI Programming with MacRuby

  • 1.
  • 2.
    GUI Programming with MacRuby Who? What? When? Where? Why? How?
  • 3.
  • 4.
  • 5.
  • 6.
    Code for America APPLY WITHIN
  • 7.
    I’ve committed to... rails oauth2 rvm rails_admin faraday bunder merb_admin thor travis-ci twitter multi_json dummy_data twurl multi_xml git-pulls simple_oauth octokit mlb
  • 8.
  • 9.
    Who else? @lrz @benstiglitz @merbist @importantshock @rich_kilmer @naixn @alloy @watson1978 @vincentisambart @Psychs @macruby macruby-devel
  • 10.
  • 11.
    What MacRuby 1. A complete implementation of Ruby 1.9
  • 12.
    Ruby apps MacRuby apps
  • 13.
  • 14.
    What MacRuby 1. A complete implementation of Ruby 1.9 2. Allows you to script existing Mac apps 3. Allows you to create new Mac apps
  • 15.
    Let me tellyou a secret...
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
    Ruby Array Initializationand Assignment array = []
  • 22.
    Objective-C Array Initializationand Assignment NSMutableArray *array = [[NSMutableArray alloc] init];
  • 23.
  • 25.
    MacRuby Hello World require'hotcocoa' include HotCocoa application do |app|   win = window :size => [100,50]   b = button :title => 'Hello'   b.on_action { puts 'World!' }   win << b end
  • 26.
    RubyCocoa Hello World require'osx/cocoa' include OSX app = NSApplication.sharedApplication win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(   [0, 0, 200, 60],   NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,   NSBackingStoreBuffered, false) win.title = 'Hello World' button = NSButton.alloc.initWithFrame(NSZeroRect) win.contentView.addSubview(button) button.bezelStyle = NSRoundedBezelStyle button.title = 'Hello!' button.sizeToFit button.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0),   (win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0)) button_controller = Object.new def button_controller.sayHello(sender)   puts "Hello World!" end button.target = button_controller button.action = 'sayHello:' win.display win.orderFrontRegardless app.run
  • 27.
  • 28.
  • 29.
  • 30.
    When MacRuby NOW! Version 0.10 Version 1.0 coming soon
  • 31.
    When MacRuby MacRuby will be included with Mac OS X 10.7 Lion* *currently as a private framework :(
  • 32.
  • 33.
    Why MacRuby • You already know Ruby • Use existing Ruby gems • Ruby 1.9.2 • No GIL • Multi-threaded generational GC • Fast!
  • 34.
    Performance Benchmarks 8 Ruby 1.9 MacRuby 7 6 5 4 3 2 1 app_answer app_tarai so_object vm1_ivar_set vm2_proc vm2_zsuper
  • 35.
    Average Selling Price $12.00 $10.00 $8.00 $6.00 $11.21 $4.00 $2.00 $4.19 $1.57 iPhone iPad Mac
  • 36.
  • 37.
    How MacRuby macruby.com
  • 38.
    How MacRuby rvm get head rvm install macruby
  • 40.
    How MacRuby brew install llvm port install llvm
  • 42.
    How MacRuby Free with ADC account at developer.apple.com/tools/xcode or $4.99 on the Mac App Store
  • 46.