Ruby Motion
IOS with the Power of Ruby
Aaron Renner / @bayfieldcoder
Animas Code Labs
Why it's Cool
- Harness power of Ruby
- Can use Objective-C directly
- Do more with less
- Wrappers
How it works
Power of Ruby
Objective C
NSMutableArray *arr = [NSMutableArray withObjects:@"Durango",@"Bayfield", nil];
[arr addObject:@"Pagosa Springs"]
NSArray *sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
Ruby
(main)> arr = ["Durango", "Bayfield"]
=> ["Durango", "Bayfield"]
(main)> arr << "Pagosa Springs"
=> ["Durango", "Bayfield", "Pagosa Springs"]
(main)> arr.sort
=> ["Bayfield", "Durango", "Pagosa Springs"]
How it Translates
(main)> "Hello World".class.ancestors
=> [String, NSMutableString, NSString, Comparable, NSObject, Kernel]
(main)> ["Durango", "Bayfield"].class.ancestors => [Array, NSMutableArray, NSArray, Enumerable, NSObject, Kernel]
Objective C to Ruby
Objective C
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Durango Coders" message:@"Welcome to ObjectiveC" delegate:nil cancelButtonTitle:@"Let's Code" otherButtonTitles: nil]; [alert show]; return YES; }
@end
Objective C to Ruby
Ruby
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@alert = UIAlertView.alloc.initWithTitle("Durango Coders",
message: "Welcome to Ruby Motion",
delegate: nil,
cancelButtonTitle: "Let's Code",
otherButtonTitles: nil)
@alert.show
true
end
end
Wrappers
Ruby Motion
By Aaron Renner
Ruby Motion
- 1,360