rubymotion

Post on 19-May-2015

121 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Charla sobre RubyMotion por Marcos Villacampa, Betabeers Madrid 23/05/2014

TRANSCRIPT

RubyMotionProgramming OS X and iOS apps with Ruby

HiI’m @MarkVillacampa

MacRuby

Started by Laurent Sansonetti inside Apple

Initial 0.1 release in March 2008

Goal: Write OS X applications in Ruby without any performance loss

MacRubyAn implementation of the Ruby language that runs on top of the Objective-C runtime and garbage collection

Based on Ruby 1.9

Uses LLVM

Eventually "sunsetted" by Apple :(

RubyMotionCommercial product.

Write OS X and iOS applications using Ruby

Laurent Sansonetti left Apple to work on it.

Released May 3rd, 2012

Awesome community!

RubyMotionBuilt on top of MacRuby

Uses a new LLVM-based static compiler that generates optimized machine code

Memory model similar to Objective-C ARC

Based on Rake

http://www.rubymotion.com/

Cocoa

Apple's native object-oriented API for OS X and iOS

Includes a lot of different libraries

Very mature (originally developed at NeXTSTEP in the 80s)

Key concepts:RubyMotion objects are Objective-C objects

>> "Hello Betabeers!".class.ancestors => [String, NSMutableString, NSString, Comparable, NSObject, Kernel]

Key concepts:Can use Ruby & Cocoa methods

>> "Hello Madridrb!".upcase ← Ruby => "HELLO MADRIDRB!" >> "Hello Madridrb!".uppercaseString ← Cocoa => "HELLO MADRIDRB!"

Key concepts:New method syntax: named parameters

>> NSDictionary.alloc.initWithObjects(["foo"], forKeys: ["bar"]) => {"foo"=>"bar"}

1. The syntax

Objective-C:

Ruby:

a = {"foo" => ["bar", "baz"], "oof" => 2}

NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:[NSArray arrayWithObjects:@"bar", @"baz"] forKey:@"foo"]; [dict setObject:[NSNumber numberWithInt:2] forKey:@"oof"];

2. No Xcode

HelloMadridrb

app

app_delegate.rb

resources

spec

main_spec.rb

.gitignore

Rakefile

$ motion create MotionBetabeers

.rb filesMain delegate

Images, Sounds, .xib files

Tests

Configuration file

3. Gems

http://rubymotion-wrappers.com

Can't use CRuby gems ('require' is not allowed)

Many wrappers and libraries specifically created for Rubymotion and Cocoa:

https://github.com/rubymotion/motion-kit

E.g.: Motion-Kit

4. TDD

Bacon

http://www.rubymotion.com/developer-center/articles/testing/

Rspec syntax

Helpers to test touch UI in iOS

describe "Application" do before do @app = UIApplication.sharedApplication end ! it "has one window" do @app.windows.size.should == 1 end end

6. Interactive Console (REPL)

Holding and clicking in a UI element assigns that element to the self variable in the console

7. CocoaPods

CocoaPods is like RubyGems but for Ojective-C projects.

$ sudo gem install cocoapods $ pod setup $ sudo gem install motion-cocoapods

Choose a pod:https://github.com/CocoaPods/Specs

Edit Rakefile:

require 'motion-cocoapods' !Motion::Project::App.setup do |app| # ... app.pods do dependency 'Facebook-iOS-SDK' end end

8. Production Ready

http://www.rubymotion.com/apps/

Hundreds of apps in the AppStore

Used at Cabify since 2012

http://www.rubymotion.com/developer-center/

Thankswww.markvillacampa.com

Twitter: @MarkVillacampa

top related