cocoa ruby

20
RubyCocoa introduction presented by Chris Chan (iGPSD) organized Cocoahead HK

Upload: chris-chan

Post on 10-May-2015

2.456 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Cocoa Ruby

RubyCocoa introduction

presented by Chris Chan (iGPSD) organized Cocoahead HK

Page 2: Cocoa Ruby

Ruby is ...

developed by Yukihiro “Matz” Matsumoto in the early 90’s

a object oriented scripting language

everything is an object ( example: 1.even? )

dynamic type script language

the foundation of well known web development framework ( Ruby on Rails )

Page 3: Cocoa Ruby

Objective-C ...an object-oriented extension of C

a dynamically-typed language

use message handler rather than function call

add support of C++ and become Objective-C++

Objective-C++ supported by official GCC since gcc 4.1

Page 4: Cocoa Ruby

Cocoa is ...

a framework for building desktop applications

developed by NeXT in 1990’s

Apple adopt NeXT technology and built OSX

Page 5: Cocoa Ruby

RubyCocoa is ...a bridge between the Objective-C and Ruby programming language

import the Objective-C classes on demand

work by forwarding Messages by using proxy objects

able to do the method overriding to Objective-C method

Page 6: Cocoa Ruby

History for RubyCocoa

started in 2001 by Hisakuni Fujimoto

in 2002, registered on SourceForge

in 2006, joined by developer from Apple, RubyCocoa presentation made during WWDC

in 2007, included and supported in Mac OSX Leopard

information from wikipediahttp://en.wikipedia.org/wiki/RubyCocoa

Page 7: Cocoa Ruby

RubyCocoa Usage

Ruby Script that make use of the native Cocoa API ( like make use of image preview to convert image )

Interactive to the system directly

use as a tool for prototyping as you can use irb to study the Cocoa in runtime

Page 8: Cocoa Ruby

RubyCocoa weakness

Performance is not as good as Objective-C/Cocoa Application

Ruby isn’t thread-safe, developer may need to handle concurrent update by using locks

Ruby cannot dispatch native threads

Page 9: Cocoa Ruby

How to get start

For developer using Mac OSX Leopard, you have built-in support for the RubyCocoa

For developer using Tiger or earlier, you can download and install RubyCocoa

svn co https://rubycocoa.svn.sourceforge.net/svnroot/rubycocoa/trunk rubycocoa

ruby install.rb configruby install.rb setupsudo ruby install.rb install

Page 10: Cocoa Ruby

Syntax different between Objective-C and Ruby(I)

in Objective-C, sending a message named play to an object named sound

[sound play];

in Ruby, the corresponding message

sound.play

Page 11: Cocoa Ruby

Syntax different between Objective-C and Ruby(II)

in Objective-C, messages include arguments, the arguments are interleaved with tags that describe them

[sound initWithContentsOfFile:filename byReference:false];

in Ruby, the corresponding messagesound.initWithContentsOfFile(filename, :byReference, false)

*argument tags are included as parameters of the message, in this case is “byReference”

Page 12: Cocoa Ruby

Ruby irb

By using irb, you can try using rubycocoairb(main):001:0> require 'osx/cocoa'=> trueirb(main):002:0> s = OSX::NSString.stringWithString "hello" => #<OSX::OCObject:0x370976 class='NSCFString' id=0x114dee0>irb(main):003:0> s.objc_methods.sort=> ["CI_affineTransform", "CI_copyWithZone:map:", "CI_rect", "UTF8String", ...

http://www.rubycocoa.com/an-introduction-to-rubycocoa/4

Page 13: Cocoa Ruby

Example Code

Example code provided by Apple can found in here /Developer/Examples/Ruby/RubyCocoa/

Page 14: Cocoa Ruby

ActiveRecord Binding Example

/Developer/Examples/Ruby/RubyCocoa/MailDemo/MailDemoActiveRecordBindings/

Page 15: Cocoa Ruby

RealTime Image filter Demo

/Developer/Examples/Ruby/RubyCocoa/CITransitionSelectorSample

Page 16: Cocoa Ruby

You can build the next Clip it!

/Developer/Examples/Ruby/RubyCocoa/MiniBrowser

Page 17: Cocoa Ruby

More resource

http://www.rubycocoa.comThey have many great tutorial for beginner like me

http://rubycocoa.sourceforge.net/HomePage

The latest Source for RubyCocoa

Page 18: Cocoa Ruby

Books

Cocoa(R) Programming for Mac(R) OS X (3rd Edition)http://www.amazon.com/exec/obidos/ASIN/0321503619/bignerdranch-20

Ruby Cocoa ( beta book ) expected release date Nov 2008http://www.pragprog.com/titles/bmrc/rubycocoa

Page 19: Cocoa Ruby

About US

iGPSD - GPS for iPhone

we are the first company selling the hardware GPS navigation solution to iPhone users

over 500 unit of GPS cable sold in 3 months

Demo Video : http://www.youtube.com/watch?v=3o2zjs3wXmI

Page 20: Cocoa Ruby

Q&A

Our blog : http://igpsd.wordpress.com/

Our Online Store : http://store.igpsd.com/