SublimeObjC2RubyMotion
SublimeObjC2RubyMotion copied to clipboard
Convertion of ObjC blocks to Ruby
I would be nice to have ObjC blocks translation as promised, here are the snippets e.g:
Objective C blocks without params
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}]
to ruby
UIView.animateWithDuration(0.2, animations: -> { view.alpha = 0.0 })
Objective-C blocks with one params
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
to ruby
UIView.animateWithDuration(0.2,
animations:-> { view.alpha = 0.0 },
completion:-> finished { view.removeFromSuperview })
Objective-C Blocks with two arguments
[aSet enumerateObjectsUsingBlock:^(id obj, BOOL *stop){
if ([obj localizedCaseInsensitiveCompare:aString]==NSOrderedSame) {
NSLog(@"Object Found: %@", obj);
*stop = YES;
}
} ];
to ruby using different lambda syntax:
the_set.enumerateObjectsUsingBlock(lambda do |obj, stop|
if obj.localizedCaseInsensitiveCompare(the_str) == NSOrderedSame
NSLog("Object Found: %@", obj)
stop.assign(true)
end
end)
and so on
Hey @seanlilmateus!
I think some of this is done in: https://github.com/kyamaguchi/SublimeObjC2RubyMotion/blob/master/tests/test_block.py