Introduction to RubyMotion by Gant Laborde - 2013
Live Presentation Link - http://gantman.github.io/RubyMotion-Intro/
Presentation Code - https://github.com/GantMan/RubyMotion-Intro
7. RubyMotion - Wat?
/ˈro ͞obē-mōSHən/
noun trademark
1. Aproprietarytoolchain, created byHipByte SPRL, for
developingnative iOS and OS X applications on Apple devices
and computers bystaticallycompilingthe Rubyprogramming
language.
OR
Apps the Ruby Way
8. Quick Example
Objective-C button tap
[button addTarget:self action:@selector(buttonTapped:)
forControlEvents: UIControlEventTouchUpInside];
// Elsewhere
- (void)buttonTapped:(id)sender {
self.view.backgroundColor = [UIColor redColor];
}
RubyMotion button tap
button.addTarget(self, action:'button_tapped',
forControlEvents:UIControlEventTouchUpInside)
# Elsewhere
def button_tapped
self.view.backgroundColor = UIColor.redColor
end
9. Better Example
Objective-C button tap
[button addTarget:self action:@selector(buttonTapped:)
forControlEvents: UIControlEventTouchUpInside];
// Elsewhere
- (void)buttonTapped:(id)sender {
self.view.backgroundColor = [UIColor redColor];
}
RubyMotion button tap (withsugarcubegem)
button.on(:touch) do
self.view.backgroundColor = :red.uicolor
end
11. What's So Great About RubyMotion?
In my opinion
Gems and Community
Editor Independence
Testing!
Readability
NativelyCompiled
The REPL
12. RubyMotion Analogy
RubyMotion is to Objective-C
As Coffeescriptis to Javascript
... plus gems are kind of like jQueryplugins
... plus MacBacon has spec tests like Jasmine would
... plus the REPL lets you live-modifylike developer tools
... plus itcompiles and obfuscates your finalcodebase
... OK, this analogygotoutof control
13. Let's Look At Code!
Classic -Hello World
FullApp -RubyTrivia
Games!
14. Hello World
$ motion create test
Tests willfail
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = HelloWorldController.new
@window.makeKeyAndVisible
true
end
end
class HelloWorldController < UIViewController
def viewDidLoad
p "Hai"
end
end
Now tests pass!
15. Hello World - REPL
main_view = UIApplication.sharedApplication.windows[0].rootViewController.view
main_view.backgroundColor = UIColor.blueColor
OR, justcommand click the view!
# REPL input
self.backgroundColor = UIColor.whiteColor
@label = UILabel.new
@label.text = "Hello World"
@label.sizeToFit
self.addSubview(@label)
# get down from there!
@label.center = [100, 100]
OR, use sugarcube-repl's tree command.
16. Code Example #2
Ruby Trivia
sugarcube
Teacup
ProMotion
BubbleWrap
formotion
and more ...