Download - Cocoa Ruby
RubyCocoa introduction
presented by Chris Chan (iGPSD) organized Cocoahead HK
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 )
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
Cocoa is ...
a framework for building desktop applications
developed by NeXT in 1990’s
Apple adopt NeXT technology and built OSX
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
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
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
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
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
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
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”
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
Example Code
Example code provided by Apple can found in here /Developer/Examples/Ruby/RubyCocoa/
ActiveRecord Binding Example
/Developer/Examples/Ruby/RubyCocoa/MailDemo/MailDemoActiveRecordBindings/
RealTime Image filter Demo
/Developer/Examples/Ruby/RubyCocoa/CITransitionSelectorSample
You can build the next Clip it!
/Developer/Examples/Ruby/RubyCocoa/MiniBrowser
More resource
http://www.rubycocoa.comThey have many great tutorial for beginner like me
http://rubycocoa.sourceforge.net/HomePage
The latest Source for RubyCocoa
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
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
Q&A
Our blog : http://igpsd.wordpress.com/
Our Online Store : http://store.igpsd.com/