Download - MacRuby: Ruby for your Mac
MacRubyRuby for your Mac!
RubyConf 2008 - http://rubyconf.org
Laurent SansonettiRuby [email protected]
Agenda
• Apple and Ruby: a love story• Cocoa development with Ruby!• Demos!• Q&A
Apple ♥ Ruby
• 2002: Ruby 1.6.7 enters Mac OS 10.2• 2005: Ruby 1.8.2 enters Mac OS 10.4
• 2007: Ruby 1.8.6, RubyCocoa, RubyGems, Rails enter Mac OS 10.5
• In the future... Rails 2.x, Passenger, MacRuby
Apple ♥ Ruby
• 2002: Ruby 1.6.7 enters Mac OS 10.2• 2005: Ruby 1.8.2 enters Mac OS 10.4
• 2007: Ruby 1.8.6, RubyCocoa, RubyGems, Rails enter Mac OS 10.5
• In the future... Rails 2.x, Passenger, MacRuby
Our Goal
Making Mac OS X the best platform for Ruby developers
Our Goal
Making Ruby a first class citizenin Mac OS X
Our Goal
Making Ruby a first class Cocoa programming language
in Mac OS X
Why Ruby?
• Cocoa is mostly implemented in Objective-C• Objective-C and Ruby are conceptually very similar
(SmallTalk inheritance)
Source: http://www.rubyist.net/~matz/20061021.html#p01
こういうのを見てると「RubyでOS
Xで(or のために)作られたんじゃないだろうか」と感じてしまう
In 10-2006, Matz Said
Source: http://www.rubyist.net/~matz/20061021.html#p01
After seeing this (Ruby in OS X), we end up feeling "Wasn't Ruby made on
(or for) OS X?"
In 10-2006, Matz Said
Source: http://www.rubyist.net/~matz/20061021.html#p01
After seeing this (Ruby in OS X), we end up feeling "Wasn't Ruby made on
(or for) OS X?"
Not a Mac
In 10-2006, Matz Said
Mac OS X Stack
Darwin
Graphics and Media
Application Frameworks
User Experience
Mac OS X Stack
RubyCocoa
• A bridge between C / Objective-C and Ruby 1.8• Created in 2001 by FUJIMOTO Hisakuni• Bundled and supported since Mac OS X 10.5• Stable
Mac development with Ruby?
Mac development with Ruby?
Web development with Ruby?
Web development with Ruby?
Why?
• Cocoa is hard to apprehend for Ruby developers• Ruby 1.8 and RubyCocoa have performance and design
issues to be used inside Cocoa
Why?
• Cocoa is hard to apprehend for Ruby developers• Ruby 1.8 and RubyCocoa have performance and design
issues to be used inside Cocoa
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 = NSRoundedBezelStylebutton.title = 'Hello!'button.sizeToFbutton.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.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = 'sayHello:'
win.displaywin.orderFrontRegardless
app.run
RubyCocoa Hello World
Why?
• Cocoa is hard to apprehend for Ruby developers• Ruby 1.8 and RubyCocoa have performance and design
issues to be used inside Cocoa
It’s a bridge!
Problem #1
Messaging syntax is different!
Problem #2
Ruby 1.8 has green threads and is not reentrant!
Problem #3
Both runtimes have differentgarbage collectors!
Problem #4
MacRuby
• Ruby 1.9 implemented on top of Core OS technologies• Objective-C runtime and garbage collector• CoreFoundation
• In development (0.4 very soon!)• First production-ready for the end of the year
• Meant to solve the Ruby 1.8 + RubyCocoa problems!
Where is the Bridge?!
• In MacRuby:• A Ruby class is an Objective-C class• A Ruby method is an Objective-C method• A Ruby object is an Objective-C object
Source: http://www.rubyist.net/~matz/20080228.html#c05
これが成功すればRubyは名実ともにOSXの公式スクリプト言語とし
て定着するに違いない
In 02-2008, Matz Said
Text
Source: http://www.rubyist.net/~matz/20080228.html#c05
If this (MacRuby) succeeds, there is no doubt Ruby
will establish itself, both in name and in reality, as the official scripting
language for OS X.
In 02-2008, Matz Said
Text
Source: http://www.rubyist.net/~matz/20080228.html#c05
If this (MacRuby) succeeds, there is no doubt Ruby
will establish itself, both in name and in reality, as the official scripting
language for OS X.
Still not a Mac
In 02-2008, Matz SaidStill the same look
Text
MRI 1.9
YARV
MRI 1.9
ParserStdlib
Builtin Classes
Runtime
YARV
MacRuby (Today)
ParserStdlib
Builtin Classes
Runtime
YARV
MacRuby (Today)
ParserStdlib
Builtin Classes
Runtime
libobjc libauto
CoreFoundation
HotCocoa
RubyConf 2008 - http://rubyconf.org
Demos
HotCocoa
• A thin Ruby layer on top of Cocoa• Builder-like API• Rich Kilmer is our hero
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 = NSRoundedBezelStylebutton.title = 'Hello!'button.sizeToFitbutton.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.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = 'sayHello:'
win.displaywin.orderFrontRegardless
app.run
RubyCocoa Hello World
framework 'Cocoa'
app = NSApplication.sharedApplication
win = NSWindow.alloc.initWithContentRect([0, 0, 200, 60], styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask, backing:NSBackingStoreBuffered, defer:false)
win.title = 'Hello World'
button = NSButton.alloc.initWithFrame(NSZeroRect)win.contentView.addSubview(button)button.bezelStyle = NSRoundedBezelStylebutton.title = 'Hello!'button.sizeToFitbutton.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.newdef button_controller.sayHello(sender) puts "Hello World!"endbutton.target = button_controllerbutton.action = 'sayHello:'
win.displaywin.orderFrontRegardless
app.run
MacRuby Hello World
HotCocoa Hello World
HotCocoa Hello World
require 'hotcocoa'include HotCocoa
application do w = window :title => 'Hello World', :frame => [0, 0, 120, 120] b = button :title => 'Click me' b.on_action { puts 'Hello World!' } w << bend
MacRuby in the Future
• Multicore support• JIT compilation• OSA+AppleEvent
Hello I’m a Mac?
In 2010, maybe...
More Information
http://macruby.org
OS X Application Development with HotCocoa Room 3Tomorrow 5:15PM
twitter: @MacRuby
Questions?Thanks for attending!
Laurent SansonettiRuby [email protected]
RubyConf 2008 - http://rubyconf.org