Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SDRuby: When Objective-C and Ruby meet

SDRuby: When Objective-C and Ruby meet

SDRuby 2009

In 2008, 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 will explain 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 will also talk about the future of MacRuby.

Video: http://sdruby.org/podcast/58

Matt Aimonetti

February 06, 2009
Tweet

More Decks by Matt Aimonetti

Other Decks in Programming

Transcript

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

    => Objective-C MacRuby Friday, February 6, 2009
  2. $ macirb >> friends = [] => [] >> friends.class

    => NSMutableArray >> friends << "Juan" => ["Juan"] >> friends << "Denis" => ["Juan", "Denis"] Friday, February 6, 2009
  3. >> friends << {first_name: "Laurent", last_name: "Sansonetti"} => ["Juan", "Denis",

    {:first_name=>"Laurent", :last_name=>"Sansonetti"}] >> friends.length => 3 Friday, February 6, 2009
  4. >> name = "Matt Aimonetti" => "Matt Aimonetti" >> name.uppercaseString

    => "MATT AIMONETTI" >> name.upcase => "MATT AIMONETTI" Friday, February 6, 2009
  5. # 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
  6. 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
  7. class Controller def awakeFromNib @friends = [] @friendsTableView.dataSource = self

    end end set the NSTableView data source Friday, February 6, 2009
  8. RUBY HELPERS def start application :name => "Sdruby" do |app|

    app.delegate = self window(:frame => [100, 100, 500, 500], :title => "SDRuby") do |win| win << label(:text => "Hello from HotCocoa", :layout => {:start => false}) win.will_close { exit } end end end Friday, February 6, 2009
  9. set the delegation # 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 Friday, February 6, 2009
  10. NSWindow helper window(:frame => [100, 100, 500, 500], :title =>

    "SDRuby") do |win| end Friday, February 6, 2009
  11. win << web_view( :layout => {:expand => [:width, :height]}, :url

    => "http://sdruby.com") Friday, February 6, 2009