by thomasjoulin · 14y ago · 0 comments
alert = UIAlertView._alloc \
._initWithTitle _S("Hello"),
:message, _S("I'm MobiRuby"),
:delegate, nil,
:cancelButtonTitle, _S("I know!"),
:otherButtonTitles, nil
alert._show
supposed to be better than this ? alert = [[UIAlertView alloc]
initWithTitle:@"Hello"
message:@"I'm ObjC"
delegate:nil
cancelButtonTitle:@"I know!"
otherButtonTitles:nil];
[alert show];file.rb:
require 'stuff'
class foo
def something
alert = UIAlertView._alloc \
._initWithTitle _S("Hello"),
:message, _S("I'm MobiRuby"),
:delegate, nil,
:cancelButtonTitle, _S("I know!"),
:otherButtonTitles, nil
alert._show
end
end
Instead offile.h
#import <stuff>
@interface foo
-(void)something:(BOOL)what andthen:(CGRect)thisthing
@end
and then file.m #import <otherstuff>
#import <yetmorestuff>
#import "file.h"
#import <oh shit is this in the right place?.h>
#import <i think this is ok>
#define SOME_HACK
#import <this better come after that define up there.h>
@implementation foo
-(void)something:(BOOL)what butthen:(CGRect)thisthing
{
alert = [[UIAlertView alloc]
initWithTitle:@"Hello"
message:@"I'm ObjC"
delegate:nil
cancelButtonTitle:@"I know!"
otherButtonTitles:nil];
[alert show];
}
Fuck that.1. Don't Repeat Yourself. Computer have more memory than 1986.
2. Don't forget to turn on warnings-as-errors, otherwise that code above will compile and then break because (of course you noticed) the method declaration doesn't actually match the declaration but the compiler doesn't care because its a brutal hack.
Even outside of that, though, there are a LOT of things that you can do with MacRuby a lot cleaner thanks to it being Ruby over its Objective-C counterpart. Try launching an external process, for example. It's 5-8 lines of code at the very least in Objective-C (and it's not as flexible), whereas it's 1-3 easy to read lines in Ruby, depending on how much control and feedback you want.
I think as it matures, we'll see some wrappers that will make MobiRuby closer to what people are wanting to see from a Ruby-on-iOS solution; it's weird that you guys seem to have no vision for this sort of thing.