MacRuby
                           Ruby + ObjC




Friday, February 6, 2009
COCOA
             Apple's Objective-C based programming environment for
                                   Mac OS X
Frida...
COCOA


    • frameworks

    • APIs

    • accompanying          runtimes

                           Goal: native Mac ap...
OBJECTIVE-C 2.0


    • reflective

    • object-oriented

    • garbage              collection

    • 32         and 64-b...
RUBY


                           obj.method parameter




Friday, February 6, 2009
OBJECTIVE-C 2.0


                           [obj method:parameter];




Friday, February 6, 2009
RUBY


                           friends = []




Friday, February 6, 2009
OBJECTIVE-C 2.0


                NSMutableArray *friends =
             [[NSMutableArray alloc] init];




Friday, Februa...
COCOA



                       Goal => native Mac applications => ObjC




Friday, February 6, 2009
:emo:
Friday, February 6, 2009
RUBYCOCOA


                   bridge between
          the Objective-C runtime and MRI




Friday, February 6, 2009
RUBYCOCOA


               No more ObjC code to write :)




Friday, February 6, 2009
RUBYCOCOA


                    Write cocoa apps in RUBY :)




Friday, February 6, 2009
RUBYCOCOA


          potentially prohibitive cost :(




Friday, February 6, 2009
RUBYCOCOA


                           conversion cost :(




Friday, February 6, 2009
RUBYCOCOA


                       message forwarding cost :(




Friday, February 6, 2009
MacRuby




Friday, February 6, 2009
MacRuby




                           APPLE'S OPEN SOURCE
                                  PROJECT



Friday, February 6...
MacRuby




                           NOT A BRIDGE




Friday, February 6, 2009
MacRuby




                           BUILT ON TOP OF THE
                           OBJECTIVE-C RUNTIME



Friday, Febru...
MacRuby




   
 all classes 
 => Objective-C
   
 all methods 
=> Objective-C
   
 all objects 
=> Objective-C

Friday, F...
MacRuby




                           CoreFoundation




Friday, February 6, 2009
MacRuby




                           native CoreFoundation
                                  data types



Friday, Febru...
MacRuby




                           native threads




Friday, February 6, 2009
MacRuby




           Objective-C Garbage Collector




Friday, February 6, 2009
CODE EXAMPLE




Friday, February 6, 2009
$ macirb
     >> friends = []
     => []
     >> friends.class
     => NSMutableArray
     >> friends << quot;Juanquot;
  ...
>> friends << {first_name: quot;Laurentquot;,
                   last_name: quot;Sansonettiquot;}
   => [quot;Juanquot;, q...
>>           name = quot;Matt Aimonettiquot;
   =>           quot;Matt Aimonettiquot;
   >>           name.uppercaseString...
X-CODE ENVIRONMENT




Friday, February 6, 2009
FREE



                           http://developer.apple.com/TOOLS/xcode/
Friday, February 6, 2009
WELL DOCUMENTED



                            http://developer.apple.com/index.html
Friday, February 6, 2009
WELL DONE
Friday, February 6, 2009
GREAT TOOLS
Friday, February 6, 2009
NEW PROJECT
Friday, February 6, 2009
MacRuby.framework
Friday, February 6, 2009
rb_main.rb
Friday, February 6, 2009
# Loading the Cocoa framework. If you need to load more
         frameworks, you can
         # do that here too.
        ...
MainMenu.nib
Friday, February 6, 2009
Friday, February 6, 2009
V of MVC
Friday, February 6, 2009
PREPARE BINDINGS
Friday, February 6, 2009
C of MVC
Friday, February 6, 2009
class Controller
                 attr_writer :friendsTableView

                    def awakeFromNib
                    ...
class Controller
             attr_writer :friendsTableView
            end




                           ivar = outlet
F...
class Controller

                      def awakeFromNib
                      end

               end




            cal...
class Controller

                      def awakeFromNib
                        @friends = []
                        @fr...
class Controller

                   def addFriend(sender)
                   end

               end




                ...
bind the UI with the Controller
Friday, February 6, 2009
NSTableDataSource
                            informal protocol




Friday, February 6, 2009
def numberOfRowsInTableView(view)
                   end




                NSTableDataSource protocol
Friday, February 6...
def tableView( view,
                    objectValueForTableColumn:column,
                    row:index )
            end...
def tableView(view,
                            setObjectValue:object,
                            forTableColumn:column,
...
Compile
Friday, February 6, 2009
HOTCOCOA
Friday, February 6, 2009
PURE RUBY SEXINESS
Friday, February 6, 2009
NO X-CODE
Friday, February 6, 2009
RUBY DSL FOR COCOA
Friday, February 6, 2009
$ hotcocoa sdruby




Friday, February 6, 2009
$ hotcocoa sdruby




                            PROJECT SETTINGS
Friday, February 6, 2009
$ hotcocoa sdruby




                    CORE OF THE APP CODE
Friday, February 6, 2009
$ hotcocoa sdruby




                               MENU BAR
Friday, February 6, 2009
$ hotcocoa sdruby




                               RAKE TASKS
Friday, February 6, 2009
$ hotcocoa sdruby




                             APP RESOURCES
Friday, February 6, 2009
def start
      application :name => quot;Sdrubyquot; do |app|
        app.delegate = self
        window(:frame => [100, ...
application :name => quot;Sdrubyquot; do |app|
               end




                           NSApplication
Friday, Feb...
application :name => quot;Sdrubyquot; do |app|
                 app.delegate = self
               end




               ...
# file/open
                def on_open(menu)
                end

                # file/new
                def on_new(m...
window(:frame => [100, 100, 500, 500], :title => quot;SDRubyquot;) do |win|
     end




                           NSWind...
label(:text => quot;Hello from HotCocoaquot;, :layout => {:start => false})




                           NSTextField hel...
win << label(:text => quot;Hello from HotCocoaquot;)




         contentView.addSubview helper
Friday, February 6, 2009
win.will_close { exit }




                           window callback
Friday, February 6, 2009
$ macrake




Friday, February 6, 2009
USE ANY COCOA
                             FRAMEWORK



Friday, February 6, 2009
WEBKIT




Friday, February 6, 2009
framework 'webkit'




Friday, February 6, 2009
win << web_view( :layout => {:expand => [:width, :height]},
                     :url => quot;http://sdruby.comquot;)




...
Friday, February 6, 2009
$ macrake deploy

                                  Raffle.app




Friday, February 6, 2009
AND MUCH MORE




Friday, February 6, 2009
DEMO APPS




Friday, February 6, 2009
SD RUBY RAFFLE APP
Friday, February 6, 2009
¿What to do
                           with MacRuby?



Friday, February 6, 2009
WEB APP
                           CLIENT



Friday, February 6, 2009
REUSE RUBY CODE




Friday, February 6, 2009
RETHINK DESKTOP APPS




Friday, February 6, 2009
WEBKIT INTEGRATION




Friday, February 6, 2009
¿MacRuby’s future?




Friday, February 6, 2009
MUCH BETTER
                           PERFORMANCE



Friday, February 6, 2009
NEW VM




Friday, February 6, 2009
SOURCE OBFUSCATION




Friday, February 6, 2009
COMPILED CODE




Friday, February 6, 2009
OPTIMIZATIONS BASED ON
             THE UNDERLYING OS



Friday, February 6, 2009
SOLID & SUPPORTED WAY TO
          WRITE COCOA APPS



Friday, February 6, 2009
¿MAINSTREAM WAY TO WRITE
            COCOA APPS?



Friday, February 6, 2009
¿IPHONE OUTPUT?




Friday, February 6, 2009
resources:
                                       http://www.macruby.org
                            http://tinyurl.com/ma...
Props to
                              Rich Kilmer
                              (hotcocoa)
                              ...
Upcoming SlideShare
Loading in...5
×

MacRuby - When objective-c and Ruby meet

14,988

Published on

MACRUBY: WHAT'S THE BIG DEAL?

Last year, Apple released MacRuby, an open source Ruby implementation
written on top of the Objective-C runtime. Writing native MacOSX
applications in Ruby without having to pay the cost of using a bridge
is now a reality. This is an important milestone for Ruby, Apple and
the Ruby community.

Matt Aimonetti explains the implementation, show how to build
desktop applications with MacRuby & HotCocoa, and discuss why Ruby
developers should add this new tool to their utility belt. Matt also talks about the future of MacRuby.

Published in: Technology
6 Comments
27 Likes
Statistics
Notes
No Downloads
Views
Total Views
14,988
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
300
Comments
6
Likes
27
Embeds 0
No embeds

No notes for slide

MacRuby - When objective-c and Ruby meet

  1. 1. MacRuby Ruby + ObjC Friday, February 6, 2009
  2. 2. COCOA Apple's Objective-C based programming environment for Mac OS X Friday, February 6, 2009
  3. 3. COCOA • frameworks • APIs • accompanying runtimes Goal: native Mac applications Friday, February 6, 2009
  4. 4. OBJECTIVE-C 2.0 • reflective • object-oriented • garbage collection • 32 and 64-bit support Friday, February 6, 2009
  5. 5. RUBY obj.method parameter Friday, February 6, 2009
  6. 6. OBJECTIVE-C 2.0 [obj method:parameter]; Friday, February 6, 2009
  7. 7. RUBY friends = [] Friday, February 6, 2009
  8. 8. OBJECTIVE-C 2.0 NSMutableArray *friends = [[NSMutableArray alloc] init]; Friday, February 6, 2009
  9. 9. COCOA Goal => native Mac applications => ObjC Friday, February 6, 2009
  10. 10. :emo: Friday, February 6, 2009
  11. 11. RUBYCOCOA bridge between the Objective-C runtime and MRI Friday, February 6, 2009
  12. 12. RUBYCOCOA No more ObjC code to write :) Friday, February 6, 2009
  13. 13. RUBYCOCOA Write cocoa apps in RUBY :) Friday, February 6, 2009
  14. 14. RUBYCOCOA potentially prohibitive cost :( Friday, February 6, 2009
  15. 15. RUBYCOCOA conversion cost :( Friday, February 6, 2009
  16. 16. RUBYCOCOA message forwarding cost :( Friday, February 6, 2009
  17. 17. MacRuby Friday, February 6, 2009
  18. 18. MacRuby APPLE'S OPEN SOURCE PROJECT Friday, February 6, 2009
  19. 19. MacRuby NOT A BRIDGE Friday, February 6, 2009
  20. 20. MacRuby BUILT ON TOP OF THE OBJECTIVE-C RUNTIME Friday, February 6, 2009
  21. 21. MacRuby all classes => Objective-C all methods => Objective-C all objects => Objective-C Friday, February 6, 2009
  22. 22. MacRuby CoreFoundation Friday, February 6, 2009
  23. 23. MacRuby native CoreFoundation data types Friday, February 6, 2009
  24. 24. MacRuby native threads Friday, February 6, 2009
  25. 25. MacRuby Objective-C Garbage Collector Friday, February 6, 2009
  26. 26. CODE EXAMPLE Friday, February 6, 2009
  27. 27. $ macirb >> friends = [] => [] >> friends.class => NSMutableArray >> friends << quot;Juanquot; => [quot;Juanquot;] >> friends << quot;Denisquot; => [quot;Juanquot;, quot;Denisquot;] Friday, February 6, 2009
  28. 28. >> friends << {first_name: quot;Laurentquot;, last_name: quot;Sansonettiquot;} => [quot;Juanquot;, quot;Denisquot;, {:first_name=>quot;Laurentquot;, :last_name=>quot;Sansonettiquot;}] >> friends.length => 3 Friday, February 6, 2009
  29. 29. >> name = quot;Matt Aimonettiquot; => quot;Matt Aimonettiquot; >> name.uppercaseString => quot;MATT AIMONETTIquot; >> name.upcase => quot;MATT AIMONETTIquot; Friday, February 6, 2009
  30. 30. X-CODE ENVIRONMENT Friday, February 6, 2009
  31. 31. FREE http://developer.apple.com/TOOLS/xcode/ Friday, February 6, 2009
  32. 32. WELL DOCUMENTED http://developer.apple.com/index.html Friday, February 6, 2009
  33. 33. WELL DONE Friday, February 6, 2009
  34. 34. GREAT TOOLS Friday, February 6, 2009
  35. 35. NEW PROJECT Friday, February 6, 2009
  36. 36. MacRuby.framework Friday, February 6, 2009
  37. 37. rb_main.rb Friday, February 6, 2009
  38. 38. # Loading the Cocoa framework. If you need to load more frameworks, you can # do that here too. framework 'Cocoa' # Loading all the Ruby project files. dir_path = NSBundle.mainBundle.resourcePath.fileSystemRepresentation Dir.entries(dir_path).each do |path| if path != File.basename(__FILE__) and path[-3..-1] == '.rb' require(path) end end # Starting the Cocoa main loop. NSApplicationMain(0, nil) Friday, February 6, 2009
  39. 39. MainMenu.nib Friday, February 6, 2009
  40. 40. Friday, February 6, 2009
  41. 41. V of MVC Friday, February 6, 2009
  42. 42. PREPARE BINDINGS Friday, February 6, 2009
  43. 43. C of MVC Friday, February 6, 2009
  44. 44. class Controller attr_writer :friendsTableView def awakeFromNib end def numberOfRowsInTableView(view) end def tableView(view, objectValueForTableColumn:column, row:index) end def tableView(view, setObjectValue:object, forTableColumn:column, row:index) end def addFriend(sender) end end Friday, February 6, 2009
  45. 45. class Controller attr_writer :friendsTableView end ivar = outlet Friday, February 6, 2009
  46. 46. class Controller def awakeFromNib end end called when instantiated by nib Friday, February 6, 2009
  47. 47. class Controller def awakeFromNib @friends = [] @friendsTableView.dataSource = self end end set the NSTableView data source Friday, February 6, 2009
  48. 48. class Controller def addFriend(sender) end end button action Friday, February 6, 2009
  49. 49. bind the UI with the Controller Friday, February 6, 2009
  50. 50. NSTableDataSource informal protocol Friday, February 6, 2009
  51. 51. def numberOfRowsInTableView(view) end NSTableDataSource protocol Friday, February 6, 2009
  52. 52. def tableView( view, objectValueForTableColumn:column, row:index ) end NSTableView selector Friday, February 6, 2009
  53. 53. def tableView(view, setObjectValue:object, forTableColumn:column, row:index) end NSTableView selector Friday, February 6, 2009
  54. 54. Compile Friday, February 6, 2009
  55. 55. HOTCOCOA Friday, February 6, 2009
  56. 56. PURE RUBY SEXINESS Friday, February 6, 2009
  57. 57. NO X-CODE Friday, February 6, 2009
  58. 58. RUBY DSL FOR COCOA Friday, February 6, 2009
  59. 59. $ hotcocoa sdruby Friday, February 6, 2009
  60. 60. $ hotcocoa sdruby PROJECT SETTINGS Friday, February 6, 2009
  61. 61. $ hotcocoa sdruby CORE OF THE APP CODE Friday, February 6, 2009
  62. 62. $ hotcocoa sdruby MENU BAR Friday, February 6, 2009
  63. 63. $ hotcocoa sdruby RAKE TASKS Friday, February 6, 2009
  64. 64. $ hotcocoa sdruby APP RESOURCES Friday, February 6, 2009
  65. 65. def start application :name => quot;Sdrubyquot; do |app| app.delegate = self window(:frame => [100, 100, 500, 500], :title => quot;SDRubyquot;) do |win| win << label(:text => quot;Hello from HotCocoaquot;, :layout => {:start => false}) win.will_close { exit } end end end RUBY HELPERS Friday, February 6, 2009
  66. 66. application :name => quot;Sdrubyquot; do |app| end NSApplication Friday, February 6, 2009
  67. 67. application :name => quot;Sdrubyquot; do |app| app.delegate = self end set the delegation Friday, February 6, 2009
  68. 68. # file/open def on_open(menu) end # file/new def on_new(menu) end # help menu item def on_help(menu) end # window/zoom def on_zoom(menu) end # window/bring_all_to_front def on_bring_all_to_front(menu) end set the delegation Friday, February 6, 2009
  69. 69. window(:frame => [100, 100, 500, 500], :title => quot;SDRubyquot;) do |win| end NSWindow helper Friday, February 6, 2009
  70. 70. label(:text => quot;Hello from HotCocoaquot;, :layout => {:start => false}) NSTextField helper Friday, February 6, 2009
  71. 71. win << label(:text => quot;Hello from HotCocoaquot;) contentView.addSubview helper Friday, February 6, 2009
  72. 72. win.will_close { exit } window callback Friday, February 6, 2009
  73. 73. $ macrake Friday, February 6, 2009
  74. 74. USE ANY COCOA FRAMEWORK Friday, February 6, 2009
  75. 75. WEBKIT Friday, February 6, 2009
  76. 76. framework 'webkit' Friday, February 6, 2009
  77. 77. win << web_view( :layout => {:expand => [:width, :height]}, :url => quot;http://sdruby.comquot;) Friday, February 6, 2009
  78. 78. Friday, February 6, 2009
  79. 79. $ macrake deploy Raffle.app Friday, February 6, 2009
  80. 80. AND MUCH MORE Friday, February 6, 2009
  81. 81. DEMO APPS Friday, February 6, 2009
  82. 82. SD RUBY RAFFLE APP Friday, February 6, 2009
  83. 83. ¿What to do with MacRuby? Friday, February 6, 2009
  84. 84. WEB APP CLIENT Friday, February 6, 2009
  85. 85. REUSE RUBY CODE Friday, February 6, 2009
  86. 86. RETHINK DESKTOP APPS Friday, February 6, 2009
  87. 87. WEBKIT INTEGRATION Friday, February 6, 2009
  88. 88. ¿MacRuby’s future? Friday, February 6, 2009
  89. 89. MUCH BETTER PERFORMANCE Friday, February 6, 2009
  90. 90. NEW VM Friday, February 6, 2009
  91. 91. SOURCE OBFUSCATION Friday, February 6, 2009
  92. 92. COMPILED CODE Friday, February 6, 2009
  93. 93. OPTIMIZATIONS BASED ON THE UNDERLYING OS Friday, February 6, 2009
  94. 94. SOLID & SUPPORTED WAY TO WRITE COCOA APPS Friday, February 6, 2009
  95. 95. ¿MAINSTREAM WAY TO WRITE COCOA APPS? Friday, February 6, 2009
  96. 96. ¿IPHONE OUTPUT? Friday, February 6, 2009
  97. 97. resources: http://www.macruby.org http://tinyurl.com/macruby-getting-started http://macruby.org/trac/wiki/MacRubyTutorial http://github.com/masterkain/macruby http://tinyurl.com/macruby-hillegass Friday, February 6, 2009
  98. 98. Props to Rich Kilmer (hotcocoa) & Laurent Sansonetti (MacRuby) Friday, February 6, 2009
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×