Transcript
Page 1: MacRuby: Ruby for your Mac

MacRubyRuby for your Mac!

RubyConf 2008 - http://rubyconf.org

Laurent SansonettiRuby [email protected]

Page 2: MacRuby: Ruby for your Mac

Agenda

• Apple and Ruby: a love story• Cocoa development with Ruby!• Demos!• Q&A

Page 3: MacRuby: Ruby for your Mac

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

Page 4: MacRuby: Ruby for your Mac

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

Page 5: MacRuby: Ruby for your Mac

Our Goal

Making Mac OS X the best platform for Ruby developers

Page 6: MacRuby: Ruby for your Mac

Our Goal

Making Ruby a first class citizenin Mac OS X

Page 7: MacRuby: Ruby for your Mac

Our Goal

Making Ruby a first class Cocoa programming language

in Mac OS X

Page 8: MacRuby: Ruby for your Mac

Why Ruby?

• Cocoa is mostly implemented in Objective-C• Objective-C and Ruby are conceptually very similar

(SmallTalk inheritance)

Page 9: MacRuby: Ruby for your Mac

Source: http://www.rubyist.net/~matz/20061021.html#p01

こういうのを見てると「RubyでOS

Xで(or のために)作られたんじゃないだろうか」と感じてしまう

In 10-2006, Matz Said

Page 10: MacRuby: Ruby for your Mac

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

Page 11: MacRuby: Ruby for your Mac

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

Page 12: MacRuby: Ruby for your Mac

Mac OS X Stack

Page 13: MacRuby: Ruby for your Mac

Darwin

Graphics and Media

Application Frameworks

User Experience

Mac OS X Stack

Page 14: MacRuby: Ruby for your Mac

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

Page 15: MacRuby: Ruby for your Mac

Mac development with Ruby?

Page 16: MacRuby: Ruby for your Mac

Mac development with Ruby?

Page 17: MacRuby: Ruby for your Mac

Web development with Ruby?

Page 18: MacRuby: Ruby for your Mac

Web development with Ruby?

Page 19: MacRuby: Ruby for your Mac

Why?

• Cocoa is hard to apprehend for Ruby developers• Ruby 1.8 and RubyCocoa have performance and design

issues to be used inside Cocoa

Page 20: MacRuby: Ruby for your Mac

Why?

• Cocoa is hard to apprehend for Ruby developers• Ruby 1.8 and RubyCocoa have performance and design

issues to be used inside Cocoa

Page 21: MacRuby: Ruby for your Mac

RubyCocoa Hello World

Page 22: MacRuby: Ruby for your Mac

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

Page 23: MacRuby: Ruby for your Mac

Why?

• Cocoa is hard to apprehend for Ruby developers• Ruby 1.8 and RubyCocoa have performance and design

issues to be used inside Cocoa

Page 24: MacRuby: Ruby for your Mac

It’s a bridge!

Problem #1

Page 25: MacRuby: Ruby for your Mac

Messaging syntax is different!

Problem #2

Page 26: MacRuby: Ruby for your Mac

Ruby 1.8 has green threads and is not reentrant!

Problem #3

Page 27: MacRuby: Ruby for your Mac

Both runtimes have differentgarbage collectors!

Problem #4

Page 28: MacRuby: Ruby for your Mac

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!

Page 29: MacRuby: Ruby for your Mac

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

Page 30: MacRuby: Ruby for your Mac

Source: http://www.rubyist.net/~matz/20080228.html#c05

これが成功すればRubyは名実ともにOSXの公式スクリプト言語とし

て定着するに違いない

In 02-2008, Matz Said

Text

Page 31: MacRuby: Ruby for your Mac

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

Page 32: MacRuby: Ruby for your Mac

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

Page 33: MacRuby: Ruby for your Mac

MRI 1.9

Page 34: MacRuby: Ruby for your Mac

YARV

MRI 1.9

ParserStdlib

Builtin Classes

Runtime

Page 35: MacRuby: Ruby for your Mac

YARV

MacRuby (Today)

ParserStdlib

Builtin Classes

Runtime

Page 36: MacRuby: Ruby for your Mac

YARV

MacRuby (Today)

ParserStdlib

Builtin Classes

Runtime

libobjc libauto

CoreFoundation

HotCocoa

Page 37: MacRuby: Ruby for your Mac

RubyConf 2008 - http://rubyconf.org

Demos

Page 38: MacRuby: Ruby for your Mac

HotCocoa

• A thin Ruby layer on top of Cocoa• Builder-like API• Rich Kilmer is our hero

Page 39: MacRuby: Ruby for your Mac

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

Page 40: MacRuby: Ruby for your Mac

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

Page 41: MacRuby: Ruby for your Mac

HotCocoa Hello World

Page 42: MacRuby: Ruby for your Mac

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

Page 43: MacRuby: Ruby for your Mac

MacRuby in the Future

• Multicore support• JIT compilation• OSA+AppleEvent

Page 44: MacRuby: Ruby for your Mac

Hello I’m a Mac?

In 2010, maybe...

Page 45: MacRuby: Ruby for your Mac

More Information

http://macruby.org

OS X Application Development with HotCocoa Room 3Tomorrow 5:15PM

twitter: @MacRuby

Page 46: MacRuby: Ruby for your Mac

Questions?Thanks for attending!

Laurent SansonettiRuby [email protected]

RubyConf 2008 - http://rubyconf.org


Top Related