100% found this document useful (1 vote)
883 views46 pages

MacRuby: Ruby For Your Mac

Everyone wants to develop Cocoa in Ruby. It can create awesome Mac apps. But you need to develop in Objective-C. Which is not so pretty. However, they both share some of the same concepts and ideas. RubyCocoa exists, but it's a bridge. So conversion is happening and that is slow and resource intensive. And each runtime has a different garbage collector! MacRuby interprets Ruby on the Objective-C runtime. Kinda like JRuby does with the JVM. All objects in MacRuby inherit from NSObject. HotCocoa is a thin Ruby layer on top of Cocoa. He showed some code and it really looked like Ruby. Slick desktops apps for the Mac written in Ruby are coming for Christmas (the projected "Production Ready" date of MacRuby). From the audience: "What about iPhone apps?" Laurent: (said in an outrageous French accent) "I'm sorry I can not answer this question" Watch a video at http://www.bestechvideos.com/2008/12/08/rubyconf-2008-macruby-ruby-for-your-mac

Uploaded by

Best Tech Videos
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
883 views46 pages

MacRuby: Ruby For Your Mac

Everyone wants to develop Cocoa in Ruby. It can create awesome Mac apps. But you need to develop in Objective-C. Which is not so pretty. However, they both share some of the same concepts and ideas. RubyCocoa exists, but it's a bridge. So conversion is happening and that is slow and resource intensive. And each runtime has a different garbage collector! MacRuby interprets Ruby on the Objective-C runtime. Kinda like JRuby does with the JVM. All objects in MacRuby inherit from NSObject. HotCocoa is a thin Ruby layer on top of Cocoa. He showed some code and it really looked like Ruby. Slick desktops apps for the Mac written in Ruby are coming for Christmas (the projected "Production Ready" date of MacRuby). From the audience: "What about iPhone apps?" Laurent: (said in an outrageous French accent) "I'm sorry I can not answer this question" Watch a video at http://www.bestechvideos.com/2008/12/08/rubyconf-2008-macruby-ruby-for-your-mac

Uploaded by

Best Tech Videos
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MacRuby

Ruby for your Mac!

Laurent Sansonetti
Ruby Ninja
lsansonetti@[Link]

RubyConf 2008 - [Link]


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 citizen


in 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)
In 10-2006, Matz Said

こういうのを見てると「RubyでOS
Xで(or のために)作られたんじゃないだろ
うか」と感じてしまう

Source: [Link]
In 10-2006, Matz Said

After seeing this (Ruby in OS X), we


end up feeling "Wasn't Ruby made on
(or for) OS X?"

Source: [Link]
In 10-2006, Matz Said

After seeing this (Ruby in OS X), we


end up feeling "Wasn't Ruby made on
(or for) OS X?"

Not a Mac

Source: [Link]
Mac OS X Stack
Mac OS X Stack

User Experience

Application Frameworks

Graphics and Media

Darwin
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
RubyCocoa Hello World
require 'osx/cocoa'; include OSX

app = [Link]

win = [Link].initWithContentRect_styleMask_backing_defer(
[0, 0, 200, 60],
NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
NSBackingStoreBuffered,
false)
[Link] = 'Hello World'

button = [Link](NSZeroRect)
[Link](button)
[Link] = NSRoundedBezelStyle
[Link] = 'Hello!'
[Link]
[Link] = NSMakePoint(([Link] / 2.0) - ([Link] / 2.0),
([Link] / 2.0) - ([Link] / 2.0))
button_controller = [Link]
def button_controller.sayHello(sender)
puts "Hello World!"
end
[Link] = button_controller
[Link] = 'sayHello:'

[Link]
[Link]

[Link]
Why?
• Cocoa is hard to apprehend for Ruby developers
• Ruby 1.8 and RubyCocoa have performance and design
issues to be used inside Cocoa
Problem #1

It’s a bridge!
Problem #2

Messaging syntax is different!


Problem #3

Ruby 1.8 has green threads


and is not reentrant!
Problem #4

Both runtimes have different


garbage collectors!
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
In 02-2008, Matz Said

これが成功すればRubyは名実
ともにOSXの公式スクリプト言語とし
て定着するに違いない

Text

Source: [Link]
In 02-2008, Matz Said

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.
Text

Source: [Link]
In 02-2008, Matz Said
Still the same look

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.
Text

Still not a Mac

Source: [Link]
MRI 1.9
MRI 1.9

Parser
Stdlib

YARV
Builtin Classes

Runtime
MacRuby (Today)

Parser
Stdlib

YARV
Builtin Classes

Runtime
MacRuby (Today)
HotCocoa

Parser
Stdlib

YARV
Builtin Classes

Runtime CoreFoundation

libobjc libauto
Demos

RubyConf 2008 - [Link]


HotCocoa
• A thin Ruby layer on top of Cocoa
• Builder-like API
• Rich Kilmer is our hero
RubyCocoa Hello World
require 'osx/cocoa'; include OSX

app = [Link]

win = [Link].initWithContentRect_styleMask_backing_defer(
[0, 0, 200, 60],
NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
NSBackingStoreBuffered,
false)
[Link] = 'Hello World'

button = [Link](NSZeroRect)
[Link](button)
[Link] = NSRoundedBezelStyle
[Link] = 'Hello!'
[Link]
[Link] = NSMakePoint(([Link] / 2.0) - ([Link] / 2.0),
([Link] / 2.0) - ([Link] / 2.0))
button_controller = [Link]
def button_controller.sayHello(sender)
puts "Hello World!"
end
[Link] = button_controller
[Link] = 'sayHello:'

[Link]
[Link]

[Link]
MacRuby Hello World
framework 'Cocoa'

app = [Link]

win = [Link]([0, 0, 200, 60],


styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
backing:NSBackingStoreBuffered,
defer:false)

[Link] = 'Hello World'

button = [Link](NSZeroRect)
[Link](button)
[Link] = NSRoundedBezelStyle
[Link] = 'Hello!'
[Link]
[Link] = NSMakePoint(([Link] / 2.0) - ([Link] / 2.0),
([Link] / 2.0) - ([Link] / 2.0))
button_controller = [Link]
def button_controller.sayHello(sender)
puts "Hello World!"
end
[Link] = button_controller
[Link] = 'sayHello:'

[Link]
[Link]

[Link]
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 << b
end
MacRuby in the Future
• Multicore support
• JIT compilation
• OSA+AppleEvent
In 2010, maybe...

Hello I’m a Mac?


More Information

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

[Link] twitter: @MacRuby


Questions?
Thanks for attending!

Laurent Sansonetti
Ruby Ninja
lsansonetti@[Link]

RubyConf 2008 - [Link]

You might also like