On Github GantMan / RubyMotion-Intro
By Gant Laborde
Scan the QR code for all slides AND references during this talk.Avid Rubyist and generally immature guy
Co-Founder of IconoclastLabs.com
Author of Numerous RubyMotion projects and Pull Requests
Author of the book RubyMotion App Development by Packt Publishing.
RubyMotion's Monthly Meetup
meetup.RubyMotion.com@mattsgarrison
How many Ruby Devs? How many iPhone devs? How many game devs?
OR
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
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 (with sugarcube gem)
button.on(:touch) do self.view.backgroundColor = :red.uicolor end
lessLike:objectiveC:and more like_ruby
- Clay Allsopp
In my opinion
RubyMotion is to Objective-C
As Coffeescript is to Javascript
... plus gems are kind of like jQuery plugins
... plus MacBacon has spec tests like Jasmine would
... plus the REPL lets you live-modify like developer tools
... plus it compiles and obfuscates your final codebase
... OK, this analogy got out of control
$ motion create test
Tests will fail
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!
This makes an iOS application, you can build an OS X application by passing in the correct template
If you are interested in a full TDD/BDD build of Hello World, check my book
main_view = UIApplication.sharedApplication.windows[0].rootViewController.view main_view.backgroundColor = UIColor.blueColor
OR, just command 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.
Accessing the view via the UIKit framework is a pain! Fortunately, you can just command click
Can't command click because things are layered? Try sugarcube-repl's tree command.
.uicolor gets converted to objective-c. They all do! Take a look at `test = {}`, `test.class`, `test.class`, `test.class.ancestors`
A game made in one day!
Questions?
Feel free to contact me via Gant@IconoclastLabs.com
Announcements