Macruby intro

1,234 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,234
On SlideShare
0
From Embeds
0
Number of Embeds
118
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Macruby intro

  1. 1. MacRuby SHRUG 2011-02-22 Peter Lind @peter_lindMonday, February 21, 2011
  2. 2. What? • Ruby 1.9 on the Objective-C runtime • Sponsored by Apple • Apple engineers and external contributorsMonday, February 21, 2011
  3. 3. Why? • Better runtime • GC, JIT compilation, AOT compilation • Cocoa integration • Ruby classes extends NSString, NSArray etcMonday, February 21, 2011
  4. 4. How? • macruby / macirb / macgem / macrake • require ‘rubygems’ • framework ‘cocoa’Monday, February 21, 2011
  5. 5. Benefits • No GIL • Multithreaded GC • lib_dispatch • Access to Cocoa APIs • GrandCentral, Core Animation, Speech Recognition, Core LocationMonday, February 21, 2011
  6. 6. Micro-benchmark~ $ rvm use 1.8.7info: Using ruby 1.8.7 p302~ $ ruby -e "start = Time.now; def fib(inp) inp < 2 ? inp : fib(inp-1) + fib(inp-2); end; (1..30).each do |i| fib(i);end; puts Time.now - start"3.097749~ $ rvm use 1.9.2info: Using ruby 1.9.2 p0~ $ ruby -e "start = Time.now; def fib(inp) inp < 2 ? inp : fib(inp-1) + fib(inp-2); end; (1..30).each do |i| fib(i);end; puts Time.now - start"0.553159~ $ rvm use jrubyinfo: Using jruby 1.5.2~ $ ruby -e "start = Time.now; def fib(inp) inp < 2 ? inp : fib(inp-1) + fib(inp-2); end; (1..30).each do |i| fib(i);end; puts Time.now - start"0.692~ $ macruby --versionMacRuby 0.8 (ruby 1.9.2) [universal-darwin10.0, x86_64]~ $ macruby -e "start = Time.now; def fib(inp) inp < 2 ? inp : fib(inp-1) + fib(inp-2); end; (1..30).each do |i| fib(i); end; puts Time.now - start"0.19616Monday, February 21, 2011
  7. 7. DemoMonday, February 21, 2011
  8. 8. Ruby vs Objective-C main_window_controller.rb class MainWindowController < NSController attr_accessor :url, :button def start_stop(sender) #implementation end MainWindowController.h MainWindowController.m @interface DemoTakeTwoViewController : NSController { #import "DemoTakeTwoViewController.h" UITextField *url; UIButton *button; @implementation MainWindowController } @synthesize url; @property (nonatomic, retain) IBOutlet UITextField @synthesize button; *url; @property (nonatomic, retain) IBOutlet UIButton - (IBAction)startStop { *button; //implementation } - (IBAction)startStop;Monday, February 21, 2011
  9. 9. • Pro • Mac AppStore • Scratch your own itch • Fast • Test Objective-C with RSpec • Con • 50 MB Runtime penalty • Gems not working (yet) • iOSMonday, February 21, 2011
  10. 10. Sounds like fun? • http://macruby.org • /Developer/Examples/Ruby/MacRuby • http://macruby.labs.oreilly.com • http://developer.apple.com • git://github.com/peterlind/Hello-SHRUG.gitMonday, February 21, 2011

×